From f530126f3c1ceac6f7dc32cc99104f62e20ae341 Mon Sep 17 00:00:00 2001 From: Siddhant Date: Tue, 5 Apr 2016 02:01:39 +0530 Subject: [PATCH 01/91] Indeted the output of list command --- tools/steam-shell.pike | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index 7470e7a..6bfa238 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -468,7 +468,7 @@ int list(string what) toappend = "Here is a list of all "+what+" in the current room\n"; foreach(display,string str) { - a=a+(str+" "); + a=a+(str+"\n"); if(str=="Invalid command") { flag=1; @@ -476,7 +476,11 @@ int list(string what) } } if(flag==0) - write(toappend+a+"\n\n"); + { + write(toappend+"\n"); + write(sprintf("%#-80s",a)); + write("\n"); + } return 0; } From c64d70d7e8e9abb24ae4cd14ea12b46b7f8cd712 Mon Sep 17 00:00:00 2001 From: Siddhant Date: Tue, 5 Apr 2016 02:27:02 +0530 Subject: [PATCH 02/91] Moved the check for Invalid command outside the loop --- tools/steam-shell.pike | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index 6bfa238..15f131b 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -464,15 +464,17 @@ int list(string what) string a=""; if(sizeof(display)==0) toappend = "There are no "+what+" in this room\n"; + else if(display[0]=="Invalid command") + { + flag=1; + write(display[0]+"\n"); + } else - toappend = "Here is a list of all "+what+" in the current room\n"; - foreach(display,string str) { - a=a+(str+"\n"); - if(str=="Invalid command") + toappend = "Here is a list of all "+what+" in the current room\n"; + foreach(display,string str) { - flag=1; - write(str+"\n"); + a=a+(str+"\n"); } } if(flag==0) From ac065cd308639c90a00f9f1bb77df57ab36e95e0 Mon Sep 17 00:00:00 2001 From: Siddhant Date: Sun, 8 May 2016 16:15:31 +0530 Subject: [PATCH 03/91] Fixed create command for Containers --- tools/steam-shell.pike | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index 15f131b..89cb71e 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -708,8 +708,9 @@ int create_ob(string type,string name) data = ([ "link_to":link_to ]); } object myobj = create_object(type,name,desc,data); - if(type=="Room") + if(type=="Room" || type=="Container") myobj->move(OBJ(getpath())); + return 0; } From 9cce114a4adca3bb1dc671b055a0ed90545b1d8e Mon Sep 17 00:00:00 2001 From: Siddhant Date: Tue, 10 May 2016 18:32:45 +0530 Subject: [PATCH 04/91] made the improvement as discussed by not checking for the last / using getpath()[-1]==47 --- tools/steam-shell.pike | 37 +++++++------------------------------ 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index 89cb71e..5a55cc1 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -554,16 +554,8 @@ int goto_room(string where) pathobj = OBJ(where); if(!pathobj) //Relative room checking { - if(getpath()[-1]==47) //check last "/" - { - pathobj = OBJ(getpath()+where); - where=getpath()+where; - } - else - { - pathobj = OBJ(getpath()+"/"+where); - where=getpath()+"/"+where; - } + pathobj = OBJ(getpath()+"/"+where); + where=getpath()+"/"+where; } roomname = pathobj->query_attribute("OBJ_NAME"); string factory = _Server->get_factory(pathobj)->query_attribute("OBJ_NAME"); @@ -634,10 +626,7 @@ int look(string|void str) int take(string name) { string fullpath=""; - if(getpath()[-1]==47) //check last "/" - fullpath = getpath()+name; - else - fullpath = getpath()+"/"+name; + fullpath = getpath()+"/"+name; object orig_file = OBJ(fullpath); if(orig_file) { @@ -653,10 +642,7 @@ int take(string name) int gothrough(string gatename) { string fullpath = ""; - if(getpath()[-1]==47) //check last "/" - fullpath = getpath()+gatename; - else - fullpath = getpath()+"/"+gatename; + fullpath = getpath()+"/"+gatename; object gate = OBJ(fullpath); if(gate) { @@ -682,10 +668,7 @@ int gothrough(string gatename) int delete(string file_cont_name) { string fullpath=""; - if(getpath()[-1]==47) //check last "/" - fullpath = getpath()+file_cont_name; - else - fullpath = getpath()+"/"+file_cont_name; + fullpath = getpath()+"/"+file_cont_name; if(OBJ(fullpath)) return 0; return 0; @@ -718,10 +701,7 @@ int create_ob(string type,string name) int peek(string container) { string fullpath = ""; - if(getpath()[-1]==47) //check last "/" - fullpath = getpath()+container; - else - fullpath = getpath()+"/"+container; + fullpath = getpath()+"/"+container; string pathfact = _Server->get_factory(OBJ(fullpath))->query_attribute("OBJ_NAME"); if(pathfact=="Room.factory") { @@ -769,10 +749,7 @@ int inventory() int editfile(string filename) { string fullpath = ""; - if(getpath()[-1]==47) //check last "/" - fullpath = getpath()+filename; - else - fullpath = getpath()+"/"+filename; + fullpath = getpath()+"/"+filename; string pathfact = _Server->get_factory(OBJ(fullpath))->query_attribute("OBJ_NAME"); if(pathfact=="Document.factory") applaunch(OBJ(fullpath),exitnow); From 0fb14f12982b9119d14e62faf4a8affc10517d1e Mon Sep 17 00:00:00 2001 From: Siddhant Date: Tue, 10 May 2016 19:08:45 +0530 Subject: [PATCH 05/91] Added the new feature to provide destination with the create command. Working for Rooms and containers --- tools/steam-shell.pike | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index 5a55cc1..ba4abb2 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -48,7 +48,7 @@ room Describe the Room you are currently in. look Look around the Room. take Copy a object in your inventory. gothrough Go through a gate. -create Create an object (File/Container/Exit) in current Room. +create Create an object (File/Container/Exit). Provide the full path of the destination or a . if you want it in current folder. peek Peek through a container. inventory(i) List your inventory. edit Edit a file in the current Room. @@ -82,7 +82,7 @@ hilfe Help for Hilfe commands. write("Go through a gate.\n"); return; case "create": - write("Create an object (File/Container/Exit) in current Room.\n"); + write("Create an object (File/Container/Exit). Provide the full path of the destination or a . if you want it in current folder.\n"); return; case "peek": write("Peek through a container.\n"); @@ -240,6 +240,8 @@ int main(int argc, array(string) argv) myarray[command_arr[0]](command_arr[1],command_arr[2]); else if(num==1) myarray[command_arr[0]](); + else if(num==4) + myarray[command_arr[0]](command_arr[1],command_arr[2],command_arr[3]); }; if(result!=0) @@ -674,7 +676,7 @@ int delete(string file_cont_name) return 0; } -int create_ob(string type,string name) +int create_ob(string type,string name,string destination) { string desc = readln->read("How would you describe it?\n"); mapping data = ([]); @@ -691,8 +693,12 @@ int create_ob(string type,string name) data = ([ "link_to":link_to ]); } object myobj = create_object(type,name,desc,data); - if(type=="Room" || type=="Container") - myobj->move(OBJ(getpath())); + if(type=="Room" || type=="Container"){ + if(destination==".") + myobj->move(OBJ(getpath())); + else + myobj->move(OBJ(destination)); + } return 0; From 404411054b7dbf12b21ad52f162d7ac07026df8e Mon Sep 17 00:00:00 2001 From: Siddhant Date: Fri, 13 May 2016 21:31:08 +0530 Subject: [PATCH 06/91] Extended the destination feature of the create command to all type of objects --- tools/steam-shell.pike | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index ba4abb2..f15d154 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -681,11 +681,13 @@ int create_ob(string type,string name,string destination) string desc = readln->read("How would you describe it?\n"); mapping data = ([]); type = String.capitalize(type); + if(destination == ".") + destination = getpath(); if(type=="Exit") { object exit_to = OBJ(readln->read("Where do you want to exit to?(full path)\n")); - object exit_from = OBJ(getpath()); - data = ([ "exit_from":exit_from, "exit_to":exit_to ]); +// object exit_from = OBJ(getpath()); + data = ([ "exit_from":OBJ(destination), "exit_to":exit_to ]); } else if(type=="Link") { @@ -693,13 +695,15 @@ int create_ob(string type,string name,string destination) data = ([ "link_to":link_to ]); } object myobj = create_object(type,name,desc,data); - if(type=="Room" || type=="Container"){ +/* if(type=="Room" || type=="Container"){ if(destination==".") myobj->move(OBJ(getpath())); else myobj->move(OBJ(destination)); } - + */ + if(!(type == "Exit")) + myobj->move(OBJ(destination)); return 0; } From b4b1ce40cd1a22a998c63fbe58569175fca8aeb7 Mon Sep 17 00:00:00 2001 From: Siddhant Date: Sun, 29 May 2016 10:07:49 +0530 Subject: [PATCH 07/91] Added the feature to open multiple files using the edit command in steam-shell --- tools/applauncher.pike | 253 +++++++++++++++++++++++++---------------- tools/steam-shell.pike | 36 ++++-- 2 files changed, 179 insertions(+), 110 deletions(-) diff --git a/tools/applauncher.pike b/tools/applauncher.pike index 8a82d7e..fe894cd 100644 --- a/tools/applauncher.pike +++ b/tools/applauncher.pike @@ -21,171 +21,224 @@ constant cvs_version="$Id: applauncher.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $"; //before using this file, patch the paths for watchforchanges.vim and golden_ratio.vim -object newfileobj; -string content; +array(object) newfileobjarr; +array(string) contentarr; int i=1; -int j=1; +int k=1; int count=0; int set=0; string dir; -string debugfile; +array(string) debugfilearr; +array(string) olderrorsarr; -void upload(object editor, string file, int last_mtime, object obj, object xslobj, function|void exit_callback, string|void olderrors) +void upload(object editor, array(string) filearr ,array(int) last_mtimearr, array(object) objarr, array(object) xslobjarr, function|void exit_callback) { int exit_status = editor->status(); - object new_stat = file_stat(file); - int new_mtime; - string newcontent; - string oldcontent = obj->get_content(); //currently changing - - if((content!=oldcontent)&&(oldcontent!=("sTeam connection lost."||""))&&obj&&(i==1)) - { + int size = sizeof(filearr); + array(object) new_statarr = allocate(size); + array(int) new_mtimearr = allocate(size); + array(string) new_errorarr = allocate(size); + for(int j=0;jget_content(); + if((contentarr[j]!=oldcontentx)&&(oldcontentx!=("sTeam connection lost."||""))&&objarr[j]&&(i==1)) + { i=0; - send_message("File changed on server.\n"); -//Not needed - Stdio.write_file(file, oldcontent||"", 0600); - last_mtime = new_stat->mtime; - } - if (!new_stat) - send_message(sprintf("%s is gone!", file)); + send_message("File changed on server.\n",debugfilearr[j]); + last_mtimearr[j] = new_statarr[j]->mtime; + } - if (new_stat && new_stat->mtime > last_mtime) - { - new_mtime = new_stat->mtime; - newcontent = Stdio.read_file(file); - if (!stringp(newcontent)) - send_message(sprintf("failed to read %s", file)); - } + if (!new_statarr[j]) + send_message(sprintf("%s is gone!", filearr[j]),debugfilearr[j]); - if (stringp(newcontent) && newcontent != content && oldcontent!="sTeam connection lost.") - { - last_mtime=new_mtime; - content = newcontent; //update initial content to new after saving - mixed result=obj->set_content(newcontent); + if (new_statarr[j] && new_statarr[j]->mtime > last_mtimearr[j]) + { + new_mtimearr[j] = new_statarr[j]->mtime; + newcontentx = Stdio.read_file(filearr[j]); + if (!stringp(newcontentx)) + send_message(sprintf("failed to read %s", filearr[j]),debugfilearr[j]); + } + + + if (stringp(newcontentx) && newcontentx != contentarr[j] && oldcontentx!="sTeam connection lost.") + { + last_mtimearr[j]=new_mtimearr[j]; + contentarr[j] = newcontentx; //update initial content to new after saving + mixed result=objarr[j]->set_content(newcontentx); string message=sprintf("File saved - upload: %O\n", result); - olderrors = UNDEFINED; - send_message(message); + olderrorsarr[j] = UNDEFINED; + send_message(message,debugfilearr[j]); count=0; //so that compile status can be rewritten for newfile - if (xslobj) + if (xslobjarr[j]) { - result=xslobj->load_xml_structure(); - message=sprintf("%O: load xml struct: %O", xslobj, result); - send_message(message); + result=xslobjarr[j]->load_xml_structure(); + message=sprintf("%O: load xml struct: %O", xslobjarr[j], result); + send_message(message,debugfilearr[j]); } - } - if(oldcontent=="sTeam connection lost.") - { - if(j==1){ - send_message("Disconnected\n"); - j--; } - if(newfileobj) + + if(oldcontentx=="sTeam connection lost.") + { + if(k==1){ + send_message("Disconnected\n",debugfilearr[j]); + k--; + } + if(newfileobjarr[j]) { - send_message("Connected back\n"); - obj = newfileobj; + send_message("Connected back\n",debugfilearr[j]); + objarr[j] = newfileobjarr[j]; } - } + } - if (exit_status != 2) - { - if(obj->get_class()=="DocLpc") //if pike script . + if (exit_status != 2) { - array errors = obj->get_errors(); - string newerrors = sprintf("%O", errors); - if (newerrors != olderrors) + if(objarr[j]->get_class()=="DocLpc") //if pike script . + { + array errors = objarr[j]->get_errors(); + // string newerrors = sprintf("%O", errors); + new_errorarr[j] = sprintf("%O", errors); + if (new_errorarr[j] != olderrorsarr[j]) { - olderrors = newerrors; - send_message("-----------------------------------------\n"); + olderrorsarr[j] = new_errorarr[j]; + send_message("-----------------------------------------\n",debugfilearr[j]); if(errors==({})) - send_message("Compiled successfully\n"); + send_message("Compiled successfully\n",debugfilearr[j]); else { foreach(errors, string err) - send_message(err); - send_message("Compilation failed\n"); + send_message(err,debugfilearr[j]); + send_message("Compilation failed\n",debugfilearr[j]); } - send_message("-----------------------------------------\n"); + send_message("-----------------------------------------\n",debugfilearr[j]); } } - call_out(upload, 1, editor, file, new_mtime, obj, xslobj, exit_callback, olderrors); - } + } else if (exit_callback) { exit_callback(editor->wait()); // exit(1); } + + } + if(exit_status !=2) + call_out(upload, 1, editor, filearr, new_mtimearr, objarr, xslobjarr, exit_callback); } -void update(object obj) +void update(array(object) obj) { - newfileobj = obj; + for(int j = 0; j < sizeof(obj); j++) + newfileobjarr[j] = obj[j]; } -array edit(object obj) +array edit(array(object) objarr) { #if constant(Crypto.Random) dir="/tmp/"+(MIME.encode_base64(Crypto.Random.random_string(10), 1)-("/"))+System.getpid(); #else dir="/tmp/"+(MIME.encode_base64(Crypto.randomness.pike_random()->read(10), 1)-("/"))+System.getpid(); #endif - string filename=obj->get_object_id()+"-"+obj->get_identifier(); + int size = sizeof(objarr); //get the number of files + contentarr=allocate(size); //made content global, this is content when vim starts and remains same. oldcontent keeps changing in upload function. + debugfilearr=allocate(size); + array(string) filenamearr = allocate(size); + - debugfile = filename+"-disp"; mkdir(dir, 0700); - content=obj->get_content(); //made content global, this is content when vim starts and remains same. oldcontent keeps changing in upload function. - //werror("%O\n", content); - Stdio.write_file(dir+"/"+filename, content||"", 0600); - - Stdio.write_file(dir+"/"+debugfile, "This is your log window\n", 0600); + + //get the filename and debugfile name for all the files + //also get content for all the files + //initialize the files + + for(int j = 0; j < size; j++){ + filenamearr[j] = objarr[j]->get_object_id()+"-"+objarr[j]->get_identifier(); + debugfilearr[j] = filenamearr[j]+"-disp"; + contentarr[j] = objarr[j]->get_content(); + filenamearr[j]=dir+"/"+filenamearr[j]; + Stdio.write_file(filenamearr[j], contentarr[j]||"", 0600); + debugfilearr[j]=dir+"/"+debugfilearr[j]; + Stdio.write_file(debugfilearr[j], "This is your log window\n", 0600); + } + + string comm;//command in string form array command; + //array command=({ "screen", "-X", "screen", "vi", dir+"/"+filename }); //array command=({ "vim", "--servername", "VIM", "--remote-wait", dir+"/"+filename }); - string enveditor = getenv("EDITOR"); - string name = dir+"/"+debugfile; - if((enveditor=="VIM")||(enveditor=="vim")) //full path to .vim files to be mentioned - command=({ "vim","-S", "/usr/local/lib/steam/tools/watchforchanges.vim", "-S", "/usr/local/lib/steam/tools/golden_ratio.vim", dir+"/"+filename, "-c","set splitbelow", "-c" ,sprintf("split|view %s",name), "-c", "wincmd w"}); + + string enveditor = getenv("EDITOR"); + + + if((enveditor=="VIM")||(enveditor=="vim")){ //full path to .vim files to be mentioned + comm="vim*-S*/usr/local/lib/steam/tools/watchforchanges.vim*-S*/usr/local/lib/steam/tools/golden_ratio.vim*-c*edit "+debugfilearr[0]+"|sp "+filenamearr[0]; + if(size>1) + comm = add_file_name(comm,filenamearr[1..],debugfilearr[1..]); + } else if(enveditor=="emacs") - command=({ "emacs", "--eval","(add-hook 'emacs-startup-hook 'toggle-window-spt)", "--eval", "(global-auto-revert-mode t)", dir+"/"+filename, dir+"/"+debugfile, "--eval", "(setq buffer-read-only t)", "--eval", sprintf("(setq frame-title-format \"%s\")",obj->get_identifier()) , "--eval", "(windmove-up)", "--eval", "(enlarge-window 5)"}); - else - command=({ "vi","-S", "/usr/local/lib/steam/tools/watchforchanges.vim", "-S", "/usr/local/lib/steam/tools/golden_ratio.vim", dir+"/"+filename, "-c","set splitbelow", "-c" ,sprintf("split|view %s",name), "-c", "wincmd w"}); + comm="emacs*--eval*(add-hook 'emacs-startup-hook 'toggle-window-spt)*--eval*(global-auto-revert-mode t)"; + for(int j = 0;jget_identifier()) +"*--eval*(windmove-up)*--eval*(enlarge-window 5)"; + else{ + comm="vi*-S*/usr/local/lib/steam/tools/watchforchanges.vim*-S*/usr/local/lib/steam/tools/golden_ratio.vim*-c*edit "+debugfilearr[0]+"|sp "+filenamearr[0]; + + if(size>1) + comm = add_file_name(comm,filenamearr[1..],debugfilearr[1..]); + } + + command=comm/"*"; // convert the string to array. object editor=Process.create_process(command, ([ "cwd":getenv("HOME"), "env":getenv(), "stdin":Stdio.stdin, "stdout":Stdio.stdout, "stderr":Stdio.stderr ])); - return ({ editor, dir+"/"+filename }); + return ({ editor,filenamearr}); } -int send_message(string message) +string add_file_name(string command,array(string) arr,array(string) debug){ + int size = sizeof(arr); + for(int j=0;jget_identifier()[sizeof(obj->get_identifier())-8..]==".xsl.xml") - { - string xslname= - obj->get_identifier()[..sizeof(obj->get_identifier())-9]+ ".xsl"; - xslobj=obj->get_environment()->get_object_byname(xslname); + int size = sizeof(objarr); + array(object) xslobjarr = allocate(size); + for(int j = 0; j < size; j++){ + if(objarr[j]->get_identifier()[sizeof(objarr[j]->get_identifier())-8..]==".xsl.xml") + { + string xslnamex= + objarr[j]->get_identifier()[..sizeof(objarr[j]->get_identifier())-9]+ ".xsl"; + xslobjarr[j]=objarr[j]->get_environment()->get_object_byname(xslnamex); + } } object editor; - string file; - [editor, file]=edit(obj); - mixed status; + array(string) filearr; + [editor,filearr]=edit(objarr); + + // mixed status; //while(!(status=editor->status())) + + array(int) filestatarr = allocate(size); + for(int j = 0; j < size; j++){ + send_message(sprintf("(opened %O %s)\n", objarr[j], filearr[j]),debugfilearr[j]); + filestatarr[j] = file_stat(filearr[j])->mtime; + } - send_message(sprintf("(opened %O %s)\n", obj, file)); - call_out(upload, 1, editor, file, file_stat(file)->mtime, obj, xslobj, exit_callback); + olderrorsarr = allocate(size); + call_out(upload, 1, editor, filearr, filestatarr, objarr, xslobjarr, exit_callback); + editor.wait(); // signal(signum("SIGINT"), prompt); + return -1; } diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index f15d154..af55da8 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -219,8 +219,7 @@ int main(int argc, array(string) argv) ]); // Regexp.SimpleRegexp a = Regexp.SimpleRegexp("[a-zA-Z]* [\"|'][a-zA-Z _-]*[\"|']"); array(string) command_arr; - while((command=readln->read( - sprintf("%s", (handler->state->finishedp()?getstring(1):getstring(2)))))) + while((command=readln->read(sprintf("%s", (handler->state->finishedp()?getstring(1):getstring(2)))))) { if(sizeof(command)) { @@ -242,10 +241,13 @@ int main(int argc, array(string) argv) myarray[command_arr[0]](); else if(num==4) myarray[command_arr[0]](command_arr[1],command_arr[2],command_arr[3]); + else + myarray[command_arr[0]](@command_arr[1..]); }; if(result!=0) { + write(result[0]); write("Wrong command.||maybe some bug.\n"); } } @@ -756,15 +758,29 @@ int inventory() display("other files", others); } -int editfile(string filename) +int editfile(string...args) { - string fullpath = ""; - fullpath = getpath()+"/"+filename; - string pathfact = _Server->get_factory(OBJ(fullpath))->query_attribute("OBJ_NAME"); - if(pathfact=="Document.factory") - applaunch(OBJ(fullpath),exitnow); - else - write("You can't edit a "+pathfact[0..sizeof(pathfact)-8]); + int size = sizeof(args); + if(size<1){ + write("Please provide a file name\n"); + return 0; + } + array(string) fullpatharr = allocate(size); + array(string) pathfactarr = allocate(size); + array(object) obj = allocate(size); + for(int j = 0;jget_factory(OBJ(fullpatharr[j]))->query_attribute("OBJ_NAME"); + + if(pathfactarr[j]!="Document.factory"){ + write("You can't edit a "+pathfactarr[j][0..sizeof(pathfactarr[j])-8]); + return 0; + } + obj[j] = OBJ(fullpatharr[j]); + } + + applaunch(obj,exitnow); + return 0; } From cd80c28b4e4df4337dc41d031cd426eb66121999 Mon Sep 17 00:00:00 2001 From: Siddhant Gupta Date: Mon, 30 May 2016 08:09:11 +0530 Subject: [PATCH 08/91] Missed braces. Fixed it --- tools/applauncher.pike | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/applauncher.pike b/tools/applauncher.pike index fe894cd..6cbf984 100644 --- a/tools/applauncher.pike +++ b/tools/applauncher.pike @@ -175,12 +175,13 @@ array edit(array(object) objarr) if(size>1) comm = add_file_name(comm,filenamearr[1..],debugfilearr[1..]); } - else if(enveditor=="emacs") + else if(enveditor=="emacs"){ comm="emacs*--eval*(add-hook 'emacs-startup-hook 'toggle-window-spt)*--eval*(global-auto-revert-mode t)"; for(int j = 0;jget_identifier()) +"*--eval*(windmove-up)*--eval*(enlarge-window 5)"; + } else{ comm="vi*-S*/usr/local/lib/steam/tools/watchforchanges.vim*-S*/usr/local/lib/steam/tools/golden_ratio.vim*-c*edit "+debugfilearr[0]+"|sp "+filenamearr[0]; From b1dbb07d276ab6d5a658bfc9a69696dbd488d3de Mon Sep 17 00:00:00 2001 From: Siddhant Date: Mon, 30 May 2016 11:05:48 +0530 Subject: [PATCH 09/91] Made edit.pike compatible with the new applaunch.pike. Note this is just a temporary solution --- tools/edit.pike | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/edit.pike b/tools/edit.pike index 3e7512f..bf3bbe3 100755 --- a/tools/edit.pike +++ b/tools/edit.pike @@ -41,7 +41,8 @@ void ping(string host, string port, string user, string|void pw) user_obj = _Server->get_module("users")->lookup(options->user); gp = user_obj->get_groups(); get_file_object(); - update(file); + array(object) filearr = ({file}); + update(filearr); } } } @@ -80,7 +81,8 @@ int main(int argc, array(string) argv) // write(mystr); // array(string) gps = ({ "Admin" , "coder" , "help" , "PrivGroups" , "WikiGroups" , "sTeam" }); get_file_object(); - return applaunch(file,demo); + array(object) filearr = ({file}); + return applaunch(filearr,demo); } void demo(){} From 54c3e653a05eb0058407337fc941d054b95d91a5 Mon Sep 17 00:00:00 2001 From: Siddhant Date: Mon, 30 May 2016 14:37:45 +0530 Subject: [PATCH 10/91] Fixed applauncher to work with edit.pike --- tools/applauncher.pike | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/applauncher.pike b/tools/applauncher.pike index 6cbf984..43a6664 100644 --- a/tools/applauncher.pike +++ b/tools/applauncher.pike @@ -128,6 +128,7 @@ void upload(object editor, array(string) filearr ,array(int) last_mtimearr, arra void update(array(object) obj) { + newfileobjarr = allocate(sizeof(obj)); for(int j = 0; j < sizeof(obj); j++) newfileobjarr[j] = obj[j]; } From 8ae84e7c59462c0bae8681960a4dccaf8b97dbec Mon Sep 17 00:00:00 2001 From: ajinkya007 Date: Mon, 30 May 2016 21:28:37 +0530 Subject: [PATCH 11/91] Incorporate chnages made in the Applauncher.pike, edit.pike and steam-shell.pike These changes have been made by Siddhant for solving the issue's #34 and #38 --- tools/applauncher.pike | 259 ++++++++++++++++++++++++---------------- tools/applauncher.pike~ | 191 +++++++++++++++++++++++++++++ tools/edit.pike | 6 +- tools/steam-shell.pike | 116 ++++++++++-------- 4 files changed, 415 insertions(+), 157 deletions(-) create mode 100644 tools/applauncher.pike~ diff --git a/tools/applauncher.pike b/tools/applauncher.pike index 8a82d7e..b3d6200 100644 --- a/tools/applauncher.pike +++ b/tools/applauncher.pike @@ -21,171 +21,226 @@ constant cvs_version="$Id: applauncher.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $"; //before using this file, patch the paths for watchforchanges.vim and golden_ratio.vim -object newfileobj; -string content; +array(object) newfileobjarr; +array(string) contentarr; int i=1; -int j=1; +int k=1; int count=0; int set=0; string dir; -string debugfile; +array(string) debugfilearr; +array(string) olderrorsarr; -void upload(object editor, string file, int last_mtime, object obj, object xslobj, function|void exit_callback, string|void olderrors) +void upload(object editor, array(string) filearr ,array(int) last_mtimearr, array(object) objarr, array(object) xslobjarr, function|void exit_callback) { int exit_status = editor->status(); - object new_stat = file_stat(file); - int new_mtime; - string newcontent; - string oldcontent = obj->get_content(); //currently changing - - if((content!=oldcontent)&&(oldcontent!=("sTeam connection lost."||""))&&obj&&(i==1)) - { + int size = sizeof(filearr); + array(object) new_statarr = allocate(size); + array(int) new_mtimearr = allocate(size); + array(string) new_errorarr = allocate(size); + for(int j=0;jget_content(); + if((contentarr[j]!=oldcontentx)&&(oldcontentx!=("sTeam connection lost."||""))&&objarr[j]&&(i==1)) + { i=0; - send_message("File changed on server.\n"); -//Not needed - Stdio.write_file(file, oldcontent||"", 0600); - last_mtime = new_stat->mtime; - } - if (!new_stat) - send_message(sprintf("%s is gone!", file)); + send_message("File changed on server.\n",debugfilearr[j]); + last_mtimearr[j] = new_statarr[j]->mtime; + } - if (new_stat && new_stat->mtime > last_mtime) - { - new_mtime = new_stat->mtime; - newcontent = Stdio.read_file(file); - if (!stringp(newcontent)) - send_message(sprintf("failed to read %s", file)); - } + if (!new_statarr[j]) + send_message(sprintf("%s is gone!", filearr[j]),debugfilearr[j]); - if (stringp(newcontent) && newcontent != content && oldcontent!="sTeam connection lost.") - { - last_mtime=new_mtime; - content = newcontent; //update initial content to new after saving - mixed result=obj->set_content(newcontent); + if (new_statarr[j] && new_statarr[j]->mtime > last_mtimearr[j]) + { + new_mtimearr[j] = new_statarr[j]->mtime; + newcontentx = Stdio.read_file(filearr[j]); + if (!stringp(newcontentx)) + send_message(sprintf("failed to read %s", filearr[j]),debugfilearr[j]); + } + + + if (stringp(newcontentx) && newcontentx != contentarr[j] && oldcontentx!="sTeam connection lost.") + { + last_mtimearr[j]=new_mtimearr[j]; + contentarr[j] = newcontentx; //update initial content to new after saving + mixed result=objarr[j]->set_content(newcontentx); string message=sprintf("File saved - upload: %O\n", result); - olderrors = UNDEFINED; - send_message(message); + olderrorsarr[j] = UNDEFINED; + send_message(message,debugfilearr[j]); count=0; //so that compile status can be rewritten for newfile - if (xslobj) + if (xslobjarr[j]) { - result=xslobj->load_xml_structure(); - message=sprintf("%O: load xml struct: %O", xslobj, result); - send_message(message); + result=xslobjarr[j]->load_xml_structure(); + message=sprintf("%O: load xml struct: %O", xslobjarr[j], result); + send_message(message,debugfilearr[j]); } - } - if(oldcontent=="sTeam connection lost.") - { - if(j==1){ - send_message("Disconnected\n"); - j--; } - if(newfileobj) + + if(oldcontentx=="sTeam connection lost.") + { + if(k==1){ + send_message("Disconnected\n",debugfilearr[j]); + k--; + } + if(newfileobjarr[j]) { - send_message("Connected back\n"); - obj = newfileobj; + send_message("Connected back\n",debugfilearr[j]); + objarr[j] = newfileobjarr[j]; } - } + } - if (exit_status != 2) - { - if(obj->get_class()=="DocLpc") //if pike script . + if (exit_status != 2) { - array errors = obj->get_errors(); - string newerrors = sprintf("%O", errors); - if (newerrors != olderrors) + if(objarr[j]->get_class()=="DocLpc") //if pike script . + { + array errors = objarr[j]->get_errors(); + // string newerrors = sprintf("%O", errors); + new_errorarr[j] = sprintf("%O", errors); + if (new_errorarr[j] != olderrorsarr[j]) { - olderrors = newerrors; - send_message("-----------------------------------------\n"); + olderrorsarr[j] = new_errorarr[j]; + send_message("-----------------------------------------\n",debugfilearr[j]); if(errors==({})) - send_message("Compiled successfully\n"); + send_message("Compiled successfully\n",debugfilearr[j]); else { foreach(errors, string err) - send_message(err); - send_message("Compilation failed\n"); + send_message(err,debugfilearr[j]); + send_message("Compilation failed\n",debugfilearr[j]); } - send_message("-----------------------------------------\n"); + send_message("-----------------------------------------\n",debugfilearr[j]); } } - call_out(upload, 1, editor, file, new_mtime, obj, xslobj, exit_callback, olderrors); - } + } else if (exit_callback) { exit_callback(editor->wait()); -// exit(1); + exit(1); } + + } + if(exit_status !=2) + call_out(upload, 1, editor, filearr, new_mtimearr, objarr, xslobjarr, exit_callback); } -void update(object obj) +void update(array(object) obj) { - newfileobj = obj; + newfileobjarr = allocate(sizeof(obj)); + for(int j = 0; j < sizeof(obj); j++) + newfileobjarr[j] = obj[j]; } -array edit(object obj) +array edit(array(object) objarr) { #if constant(Crypto.Random) dir="/tmp/"+(MIME.encode_base64(Crypto.Random.random_string(10), 1)-("/"))+System.getpid(); #else dir="/tmp/"+(MIME.encode_base64(Crypto.randomness.pike_random()->read(10), 1)-("/"))+System.getpid(); #endif - string filename=obj->get_object_id()+"-"+obj->get_identifier(); + int size = sizeof(objarr); //get the number of files + contentarr=allocate(size); //made content global, this is content when vim starts and remains same. oldcontent keeps changing in upload function. + debugfilearr=allocate(size); + array(string) filenamearr = allocate(size); + - debugfile = filename+"-disp"; mkdir(dir, 0700); - content=obj->get_content(); //made content global, this is content when vim starts and remains same. oldcontent keeps changing in upload function. - //werror("%O\n", content); - Stdio.write_file(dir+"/"+filename, content||"", 0600); - - Stdio.write_file(dir+"/"+debugfile, "This is your log window\n", 0600); + + //get the filename and debugfile name for all the files + //also get content for all the files + //initialize the files + + for(int j = 0; j < size; j++){ + filenamearr[j] = objarr[j]->get_object_id()+"-"+objarr[j]->get_identifier(); + debugfilearr[j] = filenamearr[j]+"-disp"; + contentarr[j] = objarr[j]->get_content(); + filenamearr[j]=dir+"/"+filenamearr[j]; + Stdio.write_file(filenamearr[j], contentarr[j]||"", 0600); + debugfilearr[j]=dir+"/"+debugfilearr[j]; + Stdio.write_file(debugfilearr[j], "This is your log window\n", 0600); + } + + string comm;//command in string form array command; + //array command=({ "screen", "-X", "screen", "vi", dir+"/"+filename }); //array command=({ "vim", "--servername", "VIM", "--remote-wait", dir+"/"+filename }); - string enveditor = getenv("EDITOR"); - string name = dir+"/"+debugfile; - if((enveditor=="VIM")||(enveditor=="vim")) //full path to .vim files to be mentioned - command=({ "vim","-S", "/usr/local/lib/steam/tools/watchforchanges.vim", "-S", "/usr/local/lib/steam/tools/golden_ratio.vim", dir+"/"+filename, "-c","set splitbelow", "-c" ,sprintf("split|view %s",name), "-c", "wincmd w"}); - else if(enveditor=="emacs") - command=({ "emacs", "--eval","(add-hook 'emacs-startup-hook 'toggle-window-spt)", "--eval", "(global-auto-revert-mode t)", dir+"/"+filename, dir+"/"+debugfile, "--eval", "(setq buffer-read-only t)", "--eval", sprintf("(setq frame-title-format \"%s\")",obj->get_identifier()) , "--eval", "(windmove-up)", "--eval", "(enlarge-window 5)"}); - else - command=({ "vi","-S", "/usr/local/lib/steam/tools/watchforchanges.vim", "-S", "/usr/local/lib/steam/tools/golden_ratio.vim", dir+"/"+filename, "-c","set splitbelow", "-c" ,sprintf("split|view %s",name), "-c", "wincmd w"}); + + string enveditor = getenv("EDITOR"); + + + if((enveditor=="VIM")||(enveditor=="vim")){ //full path to .vim files to be mentioned + comm="vim*-S*/usr/local/lib/steam/tools/watchforchanges.vim*-S*/usr/local/lib/steam/tools/golden_ratio.vim*-c*edit "+debugfilearr[0]+"|sp "+filenamearr[0]; + if(size>1) + comm = add_file_name(comm,filenamearr[1..],debugfilearr[1..]); + } + else if(enveditor=="emacs"){ + comm="emacs*--eval*(add-hook 'emacs-startup-hook 'toggle-window-spt)*--eval*(global-auto-revert-mode t)"; + for(int j = 0;jget_identifier()) +"*--eval*(windmove-up)*--eval*(enlarge-window 5)"; + } + else{ + comm="vi*-S*/usr/local/lib/steam/tools/watchforchanges.vim*-S*/usr/local/lib/steam/tools/golden_ratio.vim*-c*edit "+debugfilearr[0]+"|sp "+filenamearr[0]; + + if(size>1) + comm = add_file_name(comm,filenamearr[1..],debugfilearr[1..]); + } + + command=comm/"*"; // convert the string to array. object editor=Process.create_process(command, ([ "cwd":getenv("HOME"), "env":getenv(), "stdin":Stdio.stdin, "stdout":Stdio.stdout, "stderr":Stdio.stderr ])); - return ({ editor, dir+"/"+filename }); + return ({ editor,filenamearr}); } -int send_message(string message) +string add_file_name(string command,array(string) arr,array(string) debug){ + int size = sizeof(arr); + for(int j=0;jget_identifier()[sizeof(obj->get_identifier())-8..]==".xsl.xml") - { - string xslname= - obj->get_identifier()[..sizeof(obj->get_identifier())-9]+ ".xsl"; - xslobj=obj->get_environment()->get_object_byname(xslname); + int size = sizeof(objarr); + array(object) xslobjarr = allocate(size); + for(int j = 0; j < size; j++){ + if(objarr[j]->get_identifier()[sizeof(objarr[j]->get_identifier())-8..]==".xsl.xml") + { + string xslnamex= + objarr[j]->get_identifier()[..sizeof(objarr[j]->get_identifier())-9]+ ".xsl"; + xslobjarr[j]=objarr[j]->get_environment()->get_object_byname(xslnamex); + } } object editor; - string file; - [editor, file]=edit(obj); - mixed status; + array(string) filearr; + [editor,filearr]=edit(objarr); + + // mixed status; //while(!(status=editor->status())) + + array(int) filestatarr = allocate(size); + for(int j = 0; j < size; j++){ + send_message(sprintf("(opened %O %s)\n", objarr[j], filearr[j]),debugfilearr[j]); + filestatarr[j] = file_stat(filearr[j])->mtime; + } - send_message(sprintf("(opened %O %s)\n", obj, file)); - call_out(upload, 1, editor, file, file_stat(file)->mtime, obj, xslobj, exit_callback); + olderrorsarr = allocate(size); + call_out(upload, 1, editor, filearr, filestatarr, objarr, xslobjarr, exit_callback); + editor.wait(); // signal(signum("SIGINT"), prompt); + return -1; } diff --git a/tools/applauncher.pike~ b/tools/applauncher.pike~ new file mode 100644 index 0000000..8a82d7e --- /dev/null +++ b/tools/applauncher.pike~ @@ -0,0 +1,191 @@ +/* Copyright (C) 2000-2004 Thomas Bopp, Thorsten Hampel, Ludger Merkens + * Copyright (C) 2003-2004 Martin Baehr + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: applauncher.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $ + */ + +constant cvs_version="$Id: applauncher.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $"; + +//before using this file, patch the paths for watchforchanges.vim and golden_ratio.vim +object newfileobj; +string content; +int i=1; +int j=1; +int count=0; +int set=0; +string dir; +string debugfile; + +void upload(object editor, string file, int last_mtime, object obj, object xslobj, function|void exit_callback, string|void olderrors) +{ + int exit_status = editor->status(); + object new_stat = file_stat(file); + int new_mtime; + string newcontent; + string oldcontent = obj->get_content(); //currently changing + + if((content!=oldcontent)&&(oldcontent!=("sTeam connection lost."||""))&&obj&&(i==1)) + { + i=0; + send_message("File changed on server.\n"); +//Not needed - Stdio.write_file(file, oldcontent||"", 0600); + last_mtime = new_stat->mtime; + } + if (!new_stat) + send_message(sprintf("%s is gone!", file)); + + if (new_stat && new_stat->mtime > last_mtime) + { + new_mtime = new_stat->mtime; + newcontent = Stdio.read_file(file); + if (!stringp(newcontent)) + send_message(sprintf("failed to read %s", file)); + } + + if (stringp(newcontent) && newcontent != content && oldcontent!="sTeam connection lost.") + { + last_mtime=new_mtime; + content = newcontent; //update initial content to new after saving + mixed result=obj->set_content(newcontent); + string message=sprintf("File saved - upload: %O\n", result); + olderrors = UNDEFINED; + send_message(message); + count=0; //so that compile status can be rewritten for newfile + if (xslobj) + { + result=xslobj->load_xml_structure(); + message=sprintf("%O: load xml struct: %O", xslobj, result); + send_message(message); + } + } + if(oldcontent=="sTeam connection lost.") + { + if(j==1){ + send_message("Disconnected\n"); + j--; + } + if(newfileobj) + { + send_message("Connected back\n"); + obj = newfileobj; + } + } + + if (exit_status != 2) + { + if(obj->get_class()=="DocLpc") //if pike script . + { + array errors = obj->get_errors(); + string newerrors = sprintf("%O", errors); + if (newerrors != olderrors) + { + olderrors = newerrors; + send_message("-----------------------------------------\n"); + if(errors==({})) + send_message("Compiled successfully\n"); + else + { + foreach(errors, string err) + send_message(err); + send_message("Compilation failed\n"); + } + send_message("-----------------------------------------\n"); + } + } + call_out(upload, 1, editor, file, new_mtime, obj, xslobj, exit_callback, olderrors); + } + else if (exit_callback) + { + exit_callback(editor->wait()); +// exit(1); + } +} + + +void update(object obj) +{ + newfileobj = obj; +} + +array edit(object obj) +{ +#if constant(Crypto.Random) + dir="/tmp/"+(MIME.encode_base64(Crypto.Random.random_string(10), 1)-("/"))+System.getpid(); +#else + dir="/tmp/"+(MIME.encode_base64(Crypto.randomness.pike_random()->read(10), 1)-("/"))+System.getpid(); +#endif + string filename=obj->get_object_id()+"-"+obj->get_identifier(); + + debugfile = filename+"-disp"; + mkdir(dir, 0700); + content=obj->get_content(); //made content global, this is content when vim starts and remains same. oldcontent keeps changing in upload function. + //werror("%O\n", content); + Stdio.write_file(dir+"/"+filename, content||"", 0600); + + Stdio.write_file(dir+"/"+debugfile, "This is your log window\n", 0600); + array command; + //array command=({ "screen", "-X", "screen", "vi", dir+"/"+filename }); + //array command=({ "vim", "--servername", "VIM", "--remote-wait", dir+"/"+filename }); + string enveditor = getenv("EDITOR"); + string name = dir+"/"+debugfile; + if((enveditor=="VIM")||(enveditor=="vim")) //full path to .vim files to be mentioned + command=({ "vim","-S", "/usr/local/lib/steam/tools/watchforchanges.vim", "-S", "/usr/local/lib/steam/tools/golden_ratio.vim", dir+"/"+filename, "-c","set splitbelow", "-c" ,sprintf("split|view %s",name), "-c", "wincmd w"}); + else if(enveditor=="emacs") + command=({ "emacs", "--eval","(add-hook 'emacs-startup-hook 'toggle-window-spt)", "--eval", "(global-auto-revert-mode t)", dir+"/"+filename, dir+"/"+debugfile, "--eval", "(setq buffer-read-only t)", "--eval", sprintf("(setq frame-title-format \"%s\")",obj->get_identifier()) , "--eval", "(windmove-up)", "--eval", "(enlarge-window 5)"}); + else + command=({ "vi","-S", "/usr/local/lib/steam/tools/watchforchanges.vim", "-S", "/usr/local/lib/steam/tools/golden_ratio.vim", dir+"/"+filename, "-c","set splitbelow", "-c" ,sprintf("split|view %s",name), "-c", "wincmd w"}); + + object editor=Process.create_process(command, + ([ "cwd":getenv("HOME"), "env":getenv(), "stdin":Stdio.stdin, "stdout":Stdio.stdout, "stderr":Stdio.stderr ])); + return ({ editor, dir+"/"+filename }); +} + +int send_message(string message) +{ +/* + if (getenv("STY")) + Process.create_process(({ "screen", "-X", "wall", message })); + else if (getenv("TMUX")) + Process.create_process(({ "tmux", "display-message", message })); + else + werror("%s\n", message); +*/ + Stdio.append_file(dir+"/"+debugfile, message||"", 0600); //result buffer +} + +int applaunch(object obj, function exit_callback) +{ + object xslobj; + if(obj->get_identifier()[sizeof(obj->get_identifier())-8..]==".xsl.xml") + { + string xslname= + obj->get_identifier()[..sizeof(obj->get_identifier())-9]+ ".xsl"; + xslobj=obj->get_environment()->get_object_byname(xslname); + } + + object editor; + string file; + [editor, file]=edit(obj); + mixed status; + //while(!(status=editor->status())) + + send_message(sprintf("(opened %O %s)\n", obj, file)); + call_out(upload, 1, editor, file, file_stat(file)->mtime, obj, xslobj, exit_callback); + +// signal(signum("SIGINT"), prompt); + return -1; +} diff --git a/tools/edit.pike b/tools/edit.pike index 3e7512f..bf3bbe3 100755 --- a/tools/edit.pike +++ b/tools/edit.pike @@ -41,7 +41,8 @@ void ping(string host, string port, string user, string|void pw) user_obj = _Server->get_module("users")->lookup(options->user); gp = user_obj->get_groups(); get_file_object(); - update(file); + array(object) filearr = ({file}); + update(filearr); } } } @@ -80,7 +81,8 @@ int main(int argc, array(string) argv) // write(mystr); // array(string) gps = ({ "Admin" , "coder" , "help" , "PrivGroups" , "WikiGroups" , "sTeam" }); get_file_object(); - return applaunch(file,demo); + array(object) filearr = ({file}); + return applaunch(filearr,demo); } void demo(){} diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index 7470e7a..af55da8 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -48,7 +48,7 @@ room Describe the Room you are currently in. look Look around the Room. take Copy a object in your inventory. gothrough Go through a gate. -create Create an object (File/Container/Exit) in current Room. +create Create an object (File/Container/Exit). Provide the full path of the destination or a . if you want it in current folder. peek Peek through a container. inventory(i) List your inventory. edit Edit a file in the current Room. @@ -82,7 +82,7 @@ hilfe Help for Hilfe commands. write("Go through a gate.\n"); return; case "create": - write("Create an object (File/Container/Exit) in current Room.\n"); + write("Create an object (File/Container/Exit). Provide the full path of the destination or a . if you want it in current folder.\n"); return; case "peek": write("Peek through a container.\n"); @@ -219,8 +219,7 @@ int main(int argc, array(string) argv) ]); // Regexp.SimpleRegexp a = Regexp.SimpleRegexp("[a-zA-Z]* [\"|'][a-zA-Z _-]*[\"|']"); array(string) command_arr; - while((command=readln->read( - sprintf("%s", (handler->state->finishedp()?getstring(1):getstring(2)))))) + while((command=readln->read(sprintf("%s", (handler->state->finishedp()?getstring(1):getstring(2)))))) { if(sizeof(command)) { @@ -240,10 +239,15 @@ int main(int argc, array(string) argv) myarray[command_arr[0]](command_arr[1],command_arr[2]); else if(num==1) myarray[command_arr[0]](); + else if(num==4) + myarray[command_arr[0]](command_arr[1],command_arr[2],command_arr[3]); + else + myarray[command_arr[0]](@command_arr[1..]); }; if(result!=0) { + write(result[0]); write("Wrong command.||maybe some bug.\n"); } } @@ -464,19 +468,25 @@ int list(string what) string a=""; if(sizeof(display)==0) toappend = "There are no "+what+" in this room\n"; + else if(display[0]=="Invalid command") + { + flag=1; + write(display[0]+"\n"); + } else - toappend = "Here is a list of all "+what+" in the current room\n"; - foreach(display,string str) { - a=a+(str+" "); - if(str=="Invalid command") + toappend = "Here is a list of all "+what+" in the current room\n"; + foreach(display,string str) { - flag=1; - write(str+"\n"); + a=a+(str+"\n"); } } if(flag==0) - write(toappend+a+"\n\n"); + { + write(toappend+"\n"); + write(sprintf("%#-80s",a)); + write("\n"); + } return 0; } @@ -548,16 +558,8 @@ int goto_room(string where) pathobj = OBJ(where); if(!pathobj) //Relative room checking { - if(getpath()[-1]==47) //check last "/" - { - pathobj = OBJ(getpath()+where); - where=getpath()+where; - } - else - { - pathobj = OBJ(getpath()+"/"+where); - where=getpath()+"/"+where; - } + pathobj = OBJ(getpath()+"/"+where); + where=getpath()+"/"+where; } roomname = pathobj->query_attribute("OBJ_NAME"); string factory = _Server->get_factory(pathobj)->query_attribute("OBJ_NAME"); @@ -628,10 +630,7 @@ int look(string|void str) int take(string name) { string fullpath=""; - if(getpath()[-1]==47) //check last "/" - fullpath = getpath()+name; - else - fullpath = getpath()+"/"+name; + fullpath = getpath()+"/"+name; object orig_file = OBJ(fullpath); if(orig_file) { @@ -647,10 +646,7 @@ int take(string name) int gothrough(string gatename) { string fullpath = ""; - if(getpath()[-1]==47) //check last "/" - fullpath = getpath()+gatename; - else - fullpath = getpath()+"/"+gatename; + fullpath = getpath()+"/"+gatename; object gate = OBJ(fullpath); if(gate) { @@ -676,25 +672,24 @@ int gothrough(string gatename) int delete(string file_cont_name) { string fullpath=""; - if(getpath()[-1]==47) //check last "/" - fullpath = getpath()+file_cont_name; - else - fullpath = getpath()+"/"+file_cont_name; + fullpath = getpath()+"/"+file_cont_name; if(OBJ(fullpath)) return 0; return 0; } -int create_ob(string type,string name) +int create_ob(string type,string name,string destination) { string desc = readln->read("How would you describe it?\n"); mapping data = ([]); type = String.capitalize(type); + if(destination == ".") + destination = getpath(); if(type=="Exit") { object exit_to = OBJ(readln->read("Where do you want to exit to?(full path)\n")); - object exit_from = OBJ(getpath()); - data = ([ "exit_from":exit_from, "exit_to":exit_to ]); +// object exit_from = OBJ(getpath()); + data = ([ "exit_from":OBJ(destination), "exit_to":exit_to ]); } else if(type=="Link") { @@ -702,8 +697,15 @@ int create_ob(string type,string name) data = ([ "link_to":link_to ]); } object myobj = create_object(type,name,desc,data); - if(type=="Room") - myobj->move(OBJ(getpath())); +/* if(type=="Room" || type=="Container"){ + if(destination==".") + myobj->move(OBJ(getpath())); + else + myobj->move(OBJ(destination)); + } + */ + if(!(type == "Exit")) + myobj->move(OBJ(destination)); return 0; } @@ -711,10 +713,7 @@ int create_ob(string type,string name) int peek(string container) { string fullpath = ""; - if(getpath()[-1]==47) //check last "/" - fullpath = getpath()+container; - else - fullpath = getpath()+"/"+container; + fullpath = getpath()+"/"+container; string pathfact = _Server->get_factory(OBJ(fullpath))->query_attribute("OBJ_NAME"); if(pathfact=="Room.factory") { @@ -759,18 +758,29 @@ int inventory() display("other files", others); } -int editfile(string filename) +int editfile(string...args) { - string fullpath = ""; - if(getpath()[-1]==47) //check last "/" - fullpath = getpath()+filename; - else - fullpath = getpath()+"/"+filename; - string pathfact = _Server->get_factory(OBJ(fullpath))->query_attribute("OBJ_NAME"); - if(pathfact=="Document.factory") - applaunch(OBJ(fullpath),exitnow); - else - write("You can't edit a "+pathfact[0..sizeof(pathfact)-8]); + int size = sizeof(args); + if(size<1){ + write("Please provide a file name\n"); + return 0; + } + array(string) fullpatharr = allocate(size); + array(string) pathfactarr = allocate(size); + array(object) obj = allocate(size); + for(int j = 0;jget_factory(OBJ(fullpatharr[j]))->query_attribute("OBJ_NAME"); + + if(pathfactarr[j]!="Document.factory"){ + write("You can't edit a "+pathfactarr[j][0..sizeof(pathfactarr[j])-8]); + return 0; + } + obj[j] = OBJ(fullpatharr[j]); + } + + applaunch(obj,exitnow); + return 0; } From 2a8c2aedcea7af95c74cfbc7c821e6a5cde3e076 Mon Sep 17 00:00:00 2001 From: ajinkya007 Date: Mon, 30 May 2016 21:29:56 +0530 Subject: [PATCH 12/91] Remove applauncher.pike~ --- tools/applauncher.pike~ | 191 ---------------------------------------- 1 file changed, 191 deletions(-) delete mode 100644 tools/applauncher.pike~ diff --git a/tools/applauncher.pike~ b/tools/applauncher.pike~ deleted file mode 100644 index 8a82d7e..0000000 --- a/tools/applauncher.pike~ +++ /dev/null @@ -1,191 +0,0 @@ -/* Copyright (C) 2000-2004 Thomas Bopp, Thorsten Hampel, Ludger Merkens - * Copyright (C) 2003-2004 Martin Baehr - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id: applauncher.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $ - */ - -constant cvs_version="$Id: applauncher.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $"; - -//before using this file, patch the paths for watchforchanges.vim and golden_ratio.vim -object newfileobj; -string content; -int i=1; -int j=1; -int count=0; -int set=0; -string dir; -string debugfile; - -void upload(object editor, string file, int last_mtime, object obj, object xslobj, function|void exit_callback, string|void olderrors) -{ - int exit_status = editor->status(); - object new_stat = file_stat(file); - int new_mtime; - string newcontent; - string oldcontent = obj->get_content(); //currently changing - - if((content!=oldcontent)&&(oldcontent!=("sTeam connection lost."||""))&&obj&&(i==1)) - { - i=0; - send_message("File changed on server.\n"); -//Not needed - Stdio.write_file(file, oldcontent||"", 0600); - last_mtime = new_stat->mtime; - } - if (!new_stat) - send_message(sprintf("%s is gone!", file)); - - if (new_stat && new_stat->mtime > last_mtime) - { - new_mtime = new_stat->mtime; - newcontent = Stdio.read_file(file); - if (!stringp(newcontent)) - send_message(sprintf("failed to read %s", file)); - } - - if (stringp(newcontent) && newcontent != content && oldcontent!="sTeam connection lost.") - { - last_mtime=new_mtime; - content = newcontent; //update initial content to new after saving - mixed result=obj->set_content(newcontent); - string message=sprintf("File saved - upload: %O\n", result); - olderrors = UNDEFINED; - send_message(message); - count=0; //so that compile status can be rewritten for newfile - if (xslobj) - { - result=xslobj->load_xml_structure(); - message=sprintf("%O: load xml struct: %O", xslobj, result); - send_message(message); - } - } - if(oldcontent=="sTeam connection lost.") - { - if(j==1){ - send_message("Disconnected\n"); - j--; - } - if(newfileobj) - { - send_message("Connected back\n"); - obj = newfileobj; - } - } - - if (exit_status != 2) - { - if(obj->get_class()=="DocLpc") //if pike script . - { - array errors = obj->get_errors(); - string newerrors = sprintf("%O", errors); - if (newerrors != olderrors) - { - olderrors = newerrors; - send_message("-----------------------------------------\n"); - if(errors==({})) - send_message("Compiled successfully\n"); - else - { - foreach(errors, string err) - send_message(err); - send_message("Compilation failed\n"); - } - send_message("-----------------------------------------\n"); - } - } - call_out(upload, 1, editor, file, new_mtime, obj, xslobj, exit_callback, olderrors); - } - else if (exit_callback) - { - exit_callback(editor->wait()); -// exit(1); - } -} - - -void update(object obj) -{ - newfileobj = obj; -} - -array edit(object obj) -{ -#if constant(Crypto.Random) - dir="/tmp/"+(MIME.encode_base64(Crypto.Random.random_string(10), 1)-("/"))+System.getpid(); -#else - dir="/tmp/"+(MIME.encode_base64(Crypto.randomness.pike_random()->read(10), 1)-("/"))+System.getpid(); -#endif - string filename=obj->get_object_id()+"-"+obj->get_identifier(); - - debugfile = filename+"-disp"; - mkdir(dir, 0700); - content=obj->get_content(); //made content global, this is content when vim starts and remains same. oldcontent keeps changing in upload function. - //werror("%O\n", content); - Stdio.write_file(dir+"/"+filename, content||"", 0600); - - Stdio.write_file(dir+"/"+debugfile, "This is your log window\n", 0600); - array command; - //array command=({ "screen", "-X", "screen", "vi", dir+"/"+filename }); - //array command=({ "vim", "--servername", "VIM", "--remote-wait", dir+"/"+filename }); - string enveditor = getenv("EDITOR"); - string name = dir+"/"+debugfile; - if((enveditor=="VIM")||(enveditor=="vim")) //full path to .vim files to be mentioned - command=({ "vim","-S", "/usr/local/lib/steam/tools/watchforchanges.vim", "-S", "/usr/local/lib/steam/tools/golden_ratio.vim", dir+"/"+filename, "-c","set splitbelow", "-c" ,sprintf("split|view %s",name), "-c", "wincmd w"}); - else if(enveditor=="emacs") - command=({ "emacs", "--eval","(add-hook 'emacs-startup-hook 'toggle-window-spt)", "--eval", "(global-auto-revert-mode t)", dir+"/"+filename, dir+"/"+debugfile, "--eval", "(setq buffer-read-only t)", "--eval", sprintf("(setq frame-title-format \"%s\")",obj->get_identifier()) , "--eval", "(windmove-up)", "--eval", "(enlarge-window 5)"}); - else - command=({ "vi","-S", "/usr/local/lib/steam/tools/watchforchanges.vim", "-S", "/usr/local/lib/steam/tools/golden_ratio.vim", dir+"/"+filename, "-c","set splitbelow", "-c" ,sprintf("split|view %s",name), "-c", "wincmd w"}); - - object editor=Process.create_process(command, - ([ "cwd":getenv("HOME"), "env":getenv(), "stdin":Stdio.stdin, "stdout":Stdio.stdout, "stderr":Stdio.stderr ])); - return ({ editor, dir+"/"+filename }); -} - -int send_message(string message) -{ -/* - if (getenv("STY")) - Process.create_process(({ "screen", "-X", "wall", message })); - else if (getenv("TMUX")) - Process.create_process(({ "tmux", "display-message", message })); - else - werror("%s\n", message); -*/ - Stdio.append_file(dir+"/"+debugfile, message||"", 0600); //result buffer -} - -int applaunch(object obj, function exit_callback) -{ - object xslobj; - if(obj->get_identifier()[sizeof(obj->get_identifier())-8..]==".xsl.xml") - { - string xslname= - obj->get_identifier()[..sizeof(obj->get_identifier())-9]+ ".xsl"; - xslobj=obj->get_environment()->get_object_byname(xslname); - } - - object editor; - string file; - [editor, file]=edit(obj); - mixed status; - //while(!(status=editor->status())) - - send_message(sprintf("(opened %O %s)\n", obj, file)); - call_out(upload, 1, editor, file, file_stat(file)->mtime, obj, xslobj, exit_callback); - -// signal(signum("SIGINT"), prompt); - return -1; -} From 88a9543751fdd0f111876f08b3ec973eeb0fdad2 Mon Sep 17 00:00:00 2001 From: ajinkya007 Date: Mon, 30 May 2016 21:49:12 +0530 Subject: [PATCH 13/91] Steam-shell.pike can execute a command which is passed as an argument --- tools/steam-shell.pike | 1354 ++++++++++++++++++++-------------------- 1 file changed, 675 insertions(+), 679 deletions(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index af55da8..bee19ec 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -20,27 +20,32 @@ * $Id: debug.pike.in,v 1.1 2008/03/31 13:39:57 exodusd Exp $ */ -constant cvs_version="$Id: debug.pike.in,v 1.1 2008/03/31 13:39:57 exodusd Exp $"; +constant cvs_version = "$Id: debug.pike.in,v 1.1 2008/03/31 13:39:57 exodusd Exp $"; inherit "applauncher.pike"; #define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) Stdio.Readline readln; mapping options; -int flag=1,c=1; -string pw,str; +int flag = 1, c = 1; +string pw, str; object me; -protected class StashHelp { - inherit Tools.Hilfe; - string help(string what) { return "Show STASH help"; } +protected - void exec(Evaluator e, string line, array(string) words, - array(string) tokens) { - line = words[1..]*" "; - function(array(string)|string, mixed ... : void) write = e->safe_write; +class StashHelp { + inherit Tools.Hilfe; - constant all = #" + string help(string what) { + return "Show STASH help"; + } + + void exec(Evaluator e, string line, array(string) words, + array(string) tokens) { + line = words[1..]*" "; + function(array(string) | string, mixed ... : void) write = e->safe_write; + + constant all =#" list List Gates/Exits, Documents, Containers in the current Room. goto Goto a Room using a full path to the Room. title Set your own description. @@ -53,743 +58,734 @@ peek Peek through a container. inventory(i) List your inventory. edit Edit a file in the current Room. hilfe Help for Hilfe commands. -"; - switch(line) { - - case "commands": - write(all); - return; - - case "list": - write("List Gates/Exits, Documents, Containers in the current Room.\n"); - return; - case "goto": - write("Goto a Room using a full path to the Room.\n"); - return; - case "title": - write("Set your own description.\n"); - return; - case "room": - write("Describe the Room you are currently in.\n"); - return; - case "look": - write("Look around the Room.\n"); - return; - case "take": - write("Copy a object in your inventory.\n"); - return; - case "gothrough": - write("Go through a gate.\n"); - return; - case "create": - write("Create an object (File/Container/Exit). Provide the full path of the destination or a . if you want it in current folder.\n"); - return; - case "peek": - write("Peek through a container.\n"); - return; - case "i": - case "inventory": - write("Lists your inventory\n"); - return; - case "edit": - write("Edit a file in the current Room.\n"); - return; - //Hilfe internal help - case "me more": - write( documentation_help_me_more ); - write("Type \"hilfe\" to get more help on Hilfe commands\n"); - return; - case "hilfe todo": - write(hilfe_todo); - return; - case "about hilfe": - e->print_version(); - write(cvs_version+#" -Initial version written by Fredrik Hübinette 1996-2000 -Rewritten by Martin Nilsson 2002 -"); - return; - default: - write(stash_help_doc); - write(all); - write("\n\nEnter \"help me more\" for further Hilfe help.\n\n"); + "; + switch (line) { + + case "commands": + write(all); + return; + + case "list": + write("List Gates/Exits, Documents, Containers in the current Room.\n"); + return; + case "goto": + write("Goto a Room using a full path to the Room.\n"); + return; + case "title": + write("Set your own description.\n"); + return; + case "room": + write("Describe the Room you are currently in.\n"); + return; + case "look": + write("Look around the Room.\n"); + return; + case "take": + write("Copy a object in your inventory.\n"); + return; + case "gothrough": + write("Go through a gate.\n"); + return; + case "create": + write("Create an object (File/Container/Exit). Provide the full path of the destination or a . if you want it in current folder.\n"); + return; + case "peek": + write("Peek through a container.\n"); + return; + case "i": + case "inventory": + write("Lists your inventory\n"); + return; + case "edit": + write("Edit a file in the current Room.\n"); + return; + //Hilfe internal help + case "me more": + write(documentation_help_me_more); + write("Type \"hilfe\" to get more help on Hilfe commands\n"); + return; + case "hilfe todo": + write(hilfe_todo); + return; + case "about hilfe": + e->print_version(); + write(cvs_version +#" + Initial version written by Fredrik Hübinette 1996 - 2000 + Rewritten by Martin Nilsson 2002 + "); + + return; + default: + write(stash_help_doc); + write(all); + write("\n\nEnter \"help me more\" for further Hilfe help.\n\n"); + } } - } } -class Handler -{ - inherit Tools.Hilfe.Evaluator; - inherit Tools.Hilfe; - - object p; - void create(mapping _constants) - { - readln = Stdio.Readline(); - p = ((program)"tab_completion.pmod")(); - readln = p->readln; - write=predef::write; - ::create(); - p->load_hilferc(); - p->constants+=_constants; //For listing sTeam commands and objects on tab - constants = p->constants; //For running those commands - readln->get_input_controller()->bind("\t",p->handle_completions); - commands->help = StashHelp(); - commands->hilfe = CommandHelp(); - } - - void add_constants(mapping a) - { - constants = constants + a; - } -/* void add_variables(mapping a) - { - variables = variables + a; - }*/ +class Handler { + + inherit Tools.Hilfe.Evaluator; + inherit Tools.Hilfe; + + object p; + void create(mapping _constants) { + + readln = Stdio.Readline(); + p = ((program) "tab_completion.pmod")(); + readln = p->readln; + write = predef::write; + ::create(); + p->load_hilferc(); + p->constants += _constants; //For listing sTeam commands and objects on tab + constants = p->constants; //For running those commands + readln->get_input_controller()->bind("\t", p->handle_completions); + commands->help = StashHelp(); + commands->hilfe = CommandHelp(); + } + + void add_constants(mapping a) { + + constants = constants + a; + } + /* void add_variables(mapping a) + { + variables = variables + a; + }*/ } -object _Server,users; +object _Server, users; mapping all; -string path="/"; +string path = "/"; Stdio.Readline.History readline_history; -void ping() -{ - call_out(ping, 10); - mixed a = conn->send_command(14, 0); - if(a=="sTeam connection lost.") - { - flag = 0; - readln->set_prompt(getpath()+"~ "); - conn = ((program)"client_base.pike")(); - conn->close(); - if(conn->connect_server(options->host, options->port)) - { - remove_call_out(ping); - ping(); - if(str=conn->login(options->user, pw, 1)) - { - _Server=conn->SteamObj(0); - users=_Server->get_module("users"); - me = users->lookup(options->user); - handler->add_constants(assign(conn,_Server,users)); - flag=1; - readln->set_prompt(getpath()+"> "); - } - } - } +void ping() { + call_out(ping, 10); + mixed a = conn->send_command(14, 0); + if (a == "sTeam connection lost.") { + flag = 0; + readln->set_prompt(getpath() + "~ "); + conn = ((program) "client_base.pike")(); + conn->close(); + if (conn->connect_server(options->host, options->port)) { + remove_call_out(ping); + ping(); + if (str = conn->login(options->user, pw, 1)) { + + _Server = conn->SteamObj(0); + users = _Server->get_module("users"); + me = users->lookup(options->user); + handler->add_constants(assign(conn, _Server, users)); + flag = 1; + readln->set_prompt(getpath() + "> "); + } + } + } } object handler, conn; mapping myarray; -int main(int argc, array(string) argv) -{ - options=init(argv); - _Server=conn->SteamObj(0); - users=_Server->get_module("users"); - me = users->lookup(options->user); - all = assign(conn,_Server,users); - all = all + (([ - ])); - handler = Handler(all); - array history=(Stdio.read_file(options->historyfile)||"")/"\n"; - if(history[-1]!="") - history+=({""}); - - readline_history=Stdio.Readline.History(512, history); - - readln->enable_history(readline_history); - - handler->add_input_line("start backend"); - - string command; - myarray = ([ - "list" : list, - "goto" : goto_room, - "title" : set_title, - "room" : desc_room, - "look" : look, - "take" : take, - "gothrough" : gothrough, - "create" : create_ob, - "peek" : peek, - "inventory" : inventory, - "i" : inventory, - "edit" : editfile, - ]); -// Regexp.SimpleRegexp a = Regexp.SimpleRegexp("[a-zA-Z]* [\"|'][a-zA-Z _-]*[\"|']"); - array(string) command_arr; - while((command=readln->read(sprintf("%s", (handler->state->finishedp()?getstring(1):getstring(2)))))) - { - if(sizeof(command)) - { - Stdio.write_file(options->historyfile, readln->get_history()->encode()); - command = String.trim_whites(command); -// if(a->match(command)) -// command_arr = array_sscanf(command,"%s [\"|']%s[\"|']"); -// else - command_arr = command/" "; - if(myarray[command_arr[0]]) - { - int num = sizeof(command_arr); - mixed result = catch { - if(num==2) - myarray[command_arr[0]](command_arr[1]); - else if(num==3) - myarray[command_arr[0]](command_arr[1],command_arr[2]); - else if(num==1) - myarray[command_arr[0]](); - else if(num==4) - myarray[command_arr[0]](command_arr[1],command_arr[2],command_arr[3]); - else - myarray[command_arr[0]](@command_arr[1..]); - }; - - if(result!=0) - { - write(result[0]); - write("Wrong command.||maybe some bug.\n"); +array(string) command_arr; + +int main(int argc, array(string) argv) { + + options = init(argv); + _Server = conn->SteamObj(0); + users = _Server->get_module("users"); + me = users->lookup(options->user); + all = assign(conn, _Server, users); + all = all + (([ + ])); + handler = Handler(all); + array history = (Stdio.read_file(options->historyfile) || "") / "\n"; + if (history[-1] != "") + history += ({""}); + readline_history = Stdio.Readline.History(512, history); + readln->enable_history(readline_history); + handler->add_input_line("start backend"); + string command; + // Regexp.SimpleRegexp a = Regexp.SimpleRegexp("[a-zA-Z]* [\"|'][a-zA-Z _-]*[\"|']"); + + if (sizeof (argv) > 1) { + string cmd = ""; + //write("\n %s %d",cmd , sizeof(argv)); + if (sizeof (argv) >= 3){ + for (int i = 1; iread( + sprintf("%s", (handler->state->finishedp() ? getstring(1) : getstring(2)))))) { + if (sizeof (command)) { + Stdio.write_file(options->historyfile, readln->get_history()->encode()); + command = String.trim_whites(command); + // if(a->match(command)) + // command_arr = array_sscanf(command,"%s [\"|']%s[\"|']"); + // else + exec_command(command); + + // array hist = handler->history->status()/"\n"; + // if(hist) + // if(search(hist[sizeof(hist)-3],"sTeam connection lost.")!=-1){ + // handler->write("came in here\n"); + // flag=0; + // } + handler->p->set(handler->variables); + + continue; } - } - else - handler->add_input_line(command); -// array hist = handler->history->status()/"\n"; -// if(hist) -// if(search(hist[sizeof(hist)-3],"sTeam connection lost.")!=-1){ -// handler->write("came in here\n"); -// flag=0; -// } - handler->p->set(handler->variables); - continue; + // else { continue; } } -// else { continue; } - } - handler->add_input_line("exit"); + handler->add_input_line("exit"); } -mapping init(array argv) -{ - mapping options = ([ "file":"/etc/shadow" ]); +void exec_command(string command) { + myarray = ([ + "list" : list, + "goto" : goto_room, + "title" : set_title, + "room" : desc_room, + "look" : look, + "take" : take, + "gothrough" : gothrough, + "create" : create_ob, + "peek" : peek, + "inventory" : inventory, + "i" : inventory, + "edit" : editfile, + ]); + + command_arr = command / " "; + + if (myarray[command_arr[0]]) { + int num = sizeof (command_arr); + mixed result = catch { + if (num == 2) + myarray[command_arr[0]](command_arr[1]); + else if (num == 3) + myarray[command_arr[0]](command_arr[1], command_arr[2]); + else if (num == 1) + myarray[command_arr[0]](); + else if (num == 4) + myarray[command_arr[0]](command_arr[1], command_arr[2], command_arr[3]); + else + myarray[command_arr[0]](@command_arr[1..]); + }; + + if (result != 0) { + write(result[0]); + write("Wrong command.||maybe some bug.\n"); + } + } + + else + + handler->add_input_line(command); + - array opt=Getopt.find_all_options(argv,aggregate( - ({"file",Getopt.HAS_ARG,({"-f","--file"})}), - ({"host",Getopt.HAS_ARG,({"-h","--host"})}), - ({"user",Getopt.HAS_ARG,({"-u","--user"})}), - ({"port",Getopt.HAS_ARG,({"-p","--port"})}), +} +mapping init(array argv) { + + mapping options = ([ "file" : "/etc/shadow" ]); + + array opt = Getopt.find_all_options(argv, aggregate( + ({"file", Getopt.HAS_ARG, ( + {"-f", "--file"})}), + ({"host", Getopt.HAS_ARG, ( + {"-h", "--host"})}), + ({"user", Getopt.HAS_ARG, ( + {"-u", "--user"})}), + ({"port", Getopt.HAS_ARG, ( + {"-p", "--port"})}), )); - options->historyfile=getenv("HOME")+"/.steam_history"; - - foreach(opt, array option) - { - options[option[0]]=option[1]; - } - if(!options->host) - options->host="127.0.0.1"; - if(!options->user) - options->user="root"; - if(!options->port) - options->port=1900; - else - options->port=(int)options->port; - - string server_path = "/usr/local/lib/steam"; - - master()->add_include_path(server_path+"/server/include"); - master()->add_program_path(server_path+"/server/"); - master()->add_program_path(server_path+"/conf/"); - master()->add_program_path(server_path+"/spm/"); - master()->add_program_path(server_path+"/server/net/coal/"); - - conn = ((program)"client_base.pike")(); - - int start_time = time(); - - werror("Connecting to sTeam server...\n"); - while ( !conn->connect_server(options->host, options->port) ) - { - if ( time() - start_time > 120 ) - { - throw (({" Couldn't connect to server. Please check steam.log for details! \n", backtrace()})); + options->historyfile = getenv("HOME") + "/.steam_history"; + + foreach(opt, array option) { + options[option[0]] = option[1]; } - werror("Failed to connect... still trying ... (server running ?)\n"); - sleep(10); - } - - ping(); - if(lower_case(options->user) == "guest") + if (!options->host) + options->host = "127.0.0.1"; + if (!options->user) + options->user = "root"; + if (!options->port) + options->port = 1900; + else + options->port = (int) options->port; + + string server_path = "/usr/local/lib/steam"; + + master()->add_include_path(server_path + "/server/include"); + master()->add_program_path(server_path + "/server/"); + master()->add_program_path(server_path + "/conf/"); + master()->add_program_path(server_path + "/spm/"); + master()->add_program_path(server_path + "/server/net/coal/"); + + conn = ((program) "client_base.pike")(); + + int start_time = time(); + + werror("Connecting to sTeam server...\n"); + while (!conn->connect_server(options->host, options->port)) { + if (time() - start_time > 120) { + throw (({" Couldn't connect to server. Please check steam.log for details! \n", backtrace()})); + } + werror("Failed to connect... still trying ... (server running ?)\n"); + sleep(10); + } + + ping(); + if (lower_case(options->user) == "guest") + return options; + + mixed err; + int tries = 3; + //readln->set_echo( 0 ); + do { + pw = Input.read_password(sprintf("Password for %s@%s", options->user, + options->host), "steam"); + //pw=readln->read(sprintf("passwd for %s@%s: ", options->user, options->host)); + } while ((err = catch (conn->login(options->user, pw, 1))) && --tries); + //readln->set_echo( 1 ); + + if (err != 0) { + + werror("Failed to log in!\nWrong Password!\n"); + exit(1); + } return options; - - mixed err; - int tries=3; - //readln->set_echo( 0 ); - do - { - pw = Input.read_password( sprintf("Password for %s@%s", options->user, - options->host), "steam" ); - //pw=readln->read(sprintf("passwd for %s@%s: ", options->user, options->host)); - } - while((err = catch(conn->login(options->user, pw, 1))) && --tries); - //readln->set_echo( 1 ); - - if ( err != 0 ) - { - werror("Failed to log in!\nWrong Password!\n"); - exit(1); - } - return options; } -mapping assign(object conn, object _Server, object users) -{ - return ([ - "_Server" : _Server, - "get_module" : _Server->get_module, - "get_factory" : _Server->get_factory, - "conn" : conn, - "find_object" : conn->find_object, - "users" : users, - "groups" : _Server->get_module("groups"), - "me" : users->lookup(options->user), - "edit" : applaunch, - "create" : create_object, - "list" : list, - "goto" : goto_room, - "title" : set_title, - "room" : desc_room, - "look" : look, - "take" : take, - "gothrough" : gothrough, - - // from database.h : - "_SECURITY" : _Server->get_module("security"), - "_FILEPATH" : _Server->get_module("filepath:tree"), - "_TYPES" : _Server->get_module("types"), - "_LOG" : _Server->get_module("log"), - "OBJ" : _Server->get_module("filepath:tree")->path_to_object, - "MODULE_USERS" : _Server->get_module("users"), - "MODULE_GROUPS" : _Server->get_module("groups"), - "MODULE_OBJECTS" : _Server->get_module("objects"), - "MODULE_SMTP" : _Server->get_module("smtp"), - "MODULE_URL" : _Server->get_module("url"), - "MODULE_ICONS" : _Server->get_module("icons"), - "SECURITY_CACHE" : _Server->get_module("Security:cache"), - "MODULE_SERVICE" : _Server->get_module("ServiceManager"), - "MOD" : _Server->get_module, - "USER" : _Server->get_module("users")->lookup, - "GROUP" : _Server->get_module("groups")->lookup, - "_ROOTROOM" : _Server->get_module("filepath:tree")->path_to_object("/"), - "_STEAMUSER" : _Server->get_module("users")->lookup("steam"), - "_ROOT" : _Server->get_module("users")->lookup("root"), - "_GUEST" : _Server->get_module("users")->lookup("guest"), - "_ADMIN" : _Server->get_module("users")->lookup("admin"), - "_WORLDUSER" : _Server->get_module("users")->lookup("everyone"), - "_AUTHORS" : _Server->get_module("users")->lookup("authors"), - "_REVIEWER" : _Server->get_module("users")->lookup("reviewer"), - "_BUILDER" : _Server->get_module("users")->lookup("builder"), - "_CODER" : _Server->get_module("users")->lookup("coder"), - ]); +mapping assign(object conn, object _Server, object users) { + + return ([ + "_Server" : _Server, + "get_module" : _Server->get_module, + "get_factory" : _Server->get_factory, + "conn" : conn, + "find_object" : conn->find_object, + "users" : users, + "groups" : _Server->get_module("groups"), + "me" : users->lookup(options->user), + "edit" : applaunch, + "create" : create_object, + "list" : list, + "goto" : goto_room, + "title" : set_title, + "room" : desc_room, + "look" : look, + "take" : take, + "gothrough" : gothrough, + + // from database.h : + "_SECURITY" : _Server->get_module("security"), + "_FILEPATH" : _Server->get_module("filepath:tree"), + "_TYPES" : _Server->get_module("types"), + "_LOG" : _Server->get_module("log"), + "OBJ" : _Server->get_module("filepath:tree")->path_to_object, + "MODULE_USERS" : _Server->get_module("users"), + "MODULE_GROUPS" : _Server->get_module("groups"), + "MODULE_OBJECTS" : _Server->get_module("objects"), + "MODULE_SMTP" : _Server->get_module("smtp"), + "MODULE_URL" : _Server->get_module("url"), + "MODULE_ICONS" : _Server->get_module("icons"), + "SECURITY_CACHE" : _Server->get_module("Security:cache"), + "MODULE_SERVICE" : _Server->get_module("ServiceManager"), + "MOD" : _Server->get_module, + "USER" : _Server->get_module("users")->lookup, + "GROUP" : _Server->get_module("groups")->lookup, + "_ROOTROOM" : _Server->get_module("filepath:tree")->path_to_object("/"), + "_STEAMUSER" : _Server->get_module("users")->lookup("steam"), + "_ROOT" : _Server->get_module("users")->lookup("root"), + "_GUEST" : _Server->get_module("users")->lookup("guest"), + "_ADMIN" : _Server->get_module("users")->lookup("admin"), + "_WORLDUSER" : _Server->get_module("users")->lookup("everyone"), + "_AUTHORS" : _Server->get_module("users")->lookup("authors"), + "_REVIEWER" : _Server->get_module("users")->lookup("reviewer"), + "_BUILDER" : _Server->get_module("users")->lookup("builder"), + "_CODER" : _Server->get_module("users")->lookup("coder"), + ]); } // create new sTeam objects // with code taken from the web script create.pike -mixed create_object(string|void objectclass, string|void name, void|string desc, void|mapping data) -{ - if(!objectclass && !name) - { - write("Usage: create(string objectclass, string name, void|string desc, void|mapping data\n"); - return 0; - } - object _Server=conn->SteamObj(0); - object created; - object factory; - - if ( !stringp(objectclass)) - return "No object type submitted"; - - factory = _Server->get_factory(objectclass); - - switch(objectclass) - { - case "Exit": - if(!data->exit_from) - return "exit_from missing"; - break; - case "Link": - if(!data->link_to) - return "link_to missing"; - break; - } - - if(!data) - data=([]); - created = factory->execute(([ "name":name ])+ data ); - - if(stringp(desc)) - created->set_attribute("OBJ_DESC", desc); - -// if ( kind=="gallery" ) -// { -// created->set_acquire_attribute("xsl:content", 0); -// created->set_attribute("xsl:content", -// ([ _STEAMUSER:_FILEPATH->path_to_object("/stylesheets/gallery.xsl") ]) -// ); -// } - -// created->move(this_user()); - - return created; -} +mixed create_object(string | void objectclass, string | void name, void | string desc, void | mapping data) { + if (!objectclass && !name) { + write("Usage: create(string objectclass, string name, void|string desc, void|mapping data\n"); + return 0; + } + object _Server = conn->SteamObj(0); + object created; + object factory; + + if (!stringp(objectclass)) + return "No object type submitted"; + + factory = _Server->get_factory(objectclass); + + switch (objectclass) { + case "Exit": + if (!data->exit_from) + return "exit_from missing"; + break; + case "Link": + if (!data->link_to) + return "link_to missing"; + break; + } + + if (!data) + data = ([]); + created = factory->execute(([ "name" : name ]) + data); + + if (stringp(desc)) + created->set_attribute("OBJ_DESC", desc); + + // if ( kind=="gallery" ) + // { + // created->set_acquire_attribute("xsl:content", 0); + // created->set_attribute("xsl:content", + // ([ _STEAMUSER:_FILEPATH->path_to_object("/stylesheets/gallery.xsl") ]) + // ); + // } + + // created->move(this_user()); + + return created; + } -string getstring(int i) -{ -// write("came in here\n"); - string curpath = getpath(); - if(i==1&&flag==1) - return curpath+"> "; - else if(i==1&&(flag==0)) - return curpath+"~ "; - else if(i==2&&flag==1) - return curpath+">> "; - else if(i==2&&(flag==0)) - return curpath+"~~ "; -} +string getstring(int i) { + // write("came in here\n"); + string curpath = getpath(); + if (i == 1 && flag == 1) + return curpath + "> "; + else if (i == 1 && (flag == 0)) + return curpath + "~ "; + else if (i == 2 && flag == 1) + return curpath + ">> "; + else if (i == 2 && (flag == 0)) + + return curpath + "~~ "; + } -int list(string what) -{ - if(what==""||what==0) - { - write("Wrong usage\n"); - return 0; - } - int flag=0; - string toappend=""; - array(string) display = get_list(what); - string a=""; - if(sizeof(display)==0) - toappend = "There are no "+what+" in this room\n"; - else if(display[0]=="Invalid command") - { - flag=1; - write(display[0]+"\n"); +int list(string what) { + if (what == "" || what == 0) { + write("Wrong usage\n"); + return 0; } - else - { - toappend = "Here is a list of all "+what+" in the current room\n"; - foreach(display,string str) - { - a=a+(str+"\n"); + int flag = 0; + string toappend = ""; + array(string) display = get_list(what); + string a = ""; + if (sizeof (display) == 0) + toappend = "There are no " + what + " in this room\n"; + else if (display[0] == "Invalid command") { + flag = 1; + write(display[0] + "\n"); + } else { + + toappend = "Here is a list of all " + what + " in the current room\n"; + foreach(display, string str) { + a = a + (str + "\n"); + } } - } - if(flag==0) - { - write(toappend+"\n"); - write(sprintf("%#-80s",a)); - write("\n"); + if (flag == 0) { + + write(toappend + "\n"); + write(sprintf("%#-80s", a)); + write("\n"); } - return 0; + return 0; } -array(string) get_list(string what,string|object|void lpath) -{ -// string name; -// object to; - array(string) gates=({}),containers=({}),documents=({}),rooms = ({}),rest=({}); -// mapping(string:object) s = ([ ]); - object pathobj; - if(!lpath) - pathobj = OBJ(getpath()); - else if(stringp(lpath)) - pathobj = OBJ(lpath); - else if(objectp(lpath)) - pathobj = lpath; -// string pathfact = _Server->get_factory(pathobj)->query_attribute("OBJ_NAME"); - mixed all = pathobj->get_inventory_by_class(0x3cffffff); //CLASS_ALL - foreach(all, object obj) - { - string fact_name = _Server->get_factory(obj)->query_attribute("OBJ_NAME"); - string obj_name = obj->query_attribute("OBJ_NAME"); -// write("normally : "+obj_name+"\n"); - if(fact_name=="Document.factory") - documents = Array.push(documents,obj_name); -// write(obj_name+"\n"); - else if(fact_name=="Exit.factory"){ - string fullgate = obj_name+" : "+obj->get_exit()->query_attribute("OBJ_NAME"); - gates = Array.push(gates,fullgate); -// write("in gates : "+fullgate+"\n"); - } - else if(fact_name=="Container.factory") - containers = Array.push(containers,obj_name); -// write("in containers : "+obj_name+"\n"); - else if(fact_name=="Room.factory") - rooms = Array.push(rooms,obj_name); +array(string) get_list(string what, string | object | void lpath) { + // string name; + // object to; + array(string) gates = ({}), containers = ({}), documents = ({}), rooms = ({}), rest = ({}); + // mapping(string:object) s = ([ ]); + object pathobj; + if (!lpath) + pathobj = OBJ(getpath()); + else if (stringp(lpath)) + pathobj = OBJ(lpath); else - rest = Array.push(rest, obj_name); - } - if(what=="gates") - return gates; - else if(what=="rooms") - return rooms; - else if(what=="containers") - return containers; - else if(what=="files") - return documents; - else if(what=="others") - return rest; - else - return ({"Invalid command"}); -} + if (objectp(lpath)) + pathobj = lpath; + // string pathfact = _Server->get_factory(pathobj)->query_attribute("OBJ_NAME"); + mixed all = pathobj->get_inventory_by_class(0x3cffffff); //CLASS_ALL + foreach(all, object obj) { + string fact_name = _Server->get_factory(obj)->query_attribute("OBJ_NAME"); + string obj_name = obj->query_attribute("OBJ_NAME"); + // write("normally : "+obj_name+"\n"); + if (fact_name == "Document.factory") + documents = Array.push(documents, obj_name); + // write(obj_name+"\n"); + else if (fact_name == "Exit.factory") { + string fullgate = obj_name + " : " + obj->get_exit()->query_attribute("OBJ_NAME"); + gates = Array.push(gates, fullgate); + // write("in gates : "+fullgate+"\n"); + } else if (fact_name == "Container.factory") + containers = Array.push(containers, obj_name); + // write("in containers : "+obj_name+"\n"); + else if (fact_name == "Room.factory") + rooms = Array.push(rooms, obj_name); + else + rest = Array.push(rest, obj_name); + } + if (what == "gates") + return gates; + else if (what == "rooms") + return rooms; + else if (what == "containers") + return containers; + else if (what == "files") + return documents; + else if (what == "others") + return rest; -int goto_room(string where) -{ - string roomname=""; - object pathobj; - //USER CANT GO TO A RUCKSACK. HE CAN JUST LOOK INSIDE RUCKSACK -/* if(where=="rucksack") - { - pathobj=users->lookup(options->user); - path="/home/~"+pathobj->query_attribute("OBJ_NAME"); - roomname="Your rucksack"; - } -*/ -// else -// { - pathobj = OBJ(where); - if(!pathobj) //Relative room checking + else + return ({"Invalid command"}); + } + + +int goto_room(string where) { + string roomname = ""; + object pathobj; + //USER CANT GO TO A RUCKSACK. HE CAN JUST LOOK INSIDE RUCKSACK + /* if(where=="rucksack") + { + pathobj=users->lookup(options->user); + path="/home/~"+pathobj->query_attribute("OBJ_NAME"); + roomname="Your rucksack"; + } + */ + // else + // { + pathobj = OBJ(where); + if (!pathobj) //Relative room checking { - pathobj = OBJ(getpath()+"/"+where); - where=getpath()+"/"+where; + pathobj = OBJ(getpath() + "/" + where); + where = getpath() + "/" + where; } roomname = pathobj->query_attribute("OBJ_NAME"); - string factory = _Server->get_factory(pathobj)->query_attribute("OBJ_NAME"); - //DONT NEED THIS. NEED TO USE me->move() to these locations -// if(pathobj&&((factory=="Room.factory")||(factory=="User.factory")||(factory=="Container.factory"))) -// path = where; - string oldpath = getpath(); - mixed error = catch{ + string factory = _Server->get_factory(pathobj)->query_attribute("OBJ_NAME"); + //DONT NEED THIS. NEED TO USE me->move() to these locations + // if(pathobj&&((factory=="Room.factory")||(factory=="User.factory")||(factory=="Container.factory"))) + // path = where; + string oldpath = getpath(); + mixed error = catch { me->move(pathobj); - write("You are now inside "+roomname+"\n"); + write("You are now inside " + roomname + "\n"); }; - if(error && pathobj) - { - write("Please specify path to room. Not a "+((factory/".")[0])+"\n"); - me->move(OBJ(oldpath)); - } - else if(error) - { - write("Please specify correct path to a room.\n"); + if (error && pathobj) { + write("Please specify path to room. Not a " + ((factory / ".")[0]) + "\n"); + me->move(OBJ(oldpath)); + } else if (error) { + + write("Please specify correct path to a room.\n"); } -// } -// roomname = pathobj->query_attribute("OBJ_NAME"); -// write("You are now inside "+roomname+"\n"); - return 0; + // } + // roomname = pathobj->query_attribute("OBJ_NAME"); + // write("You are now inside "+roomname+"\n"); + return 0; } -int set_title(string desc) -{ - if(users->lookup(options->user)->set_attribute("OBJ_DESC",desc)) - write("You are now described as - "+desc+"\n"); - else - write("Cannot set description.\n"); - return 0; -} +int set_title(string desc) { + if (users->lookup(options->user)->set_attribute("OBJ_DESC", desc)) + write("You are now described as - " + desc + "\n"); + else + write("Cannot set description.\n"); -int desc_room() -{ -// write("path : "+path+"\n"); - object pathobj = OBJ(getpath()); - string desc = pathobj->query_attribute("OBJ_DESC"); -// write("desc : "+desc+"\n"); - if((desc=="")||(Regexp.match("^ +$",desc))) - desc = "This room does not have a description yet.\n"; - write("You are currently in "+pathobj->query_attribute("OBJ_NAME")+"\n"+desc+"\n"); - return 0; -} + return 0; + } -int look(string|void str) -{ - if(str) - { - write("Just type in 'look' to look around you\n"); - return 0; - } - desc_room(); - list("files"); - write("---------------\n"); - list("containers"); - write("---------------\n"); - list("gates"); - write("---------------\n"); - list("rooms"); - write("---------------\n"); - return 0; -} +int desc_room() { + // write("path : "+path+"\n"); + object pathobj = OBJ(getpath()); + string desc = pathobj->query_attribute("OBJ_DESC"); + // write("desc : "+desc+"\n"); + if ((desc == "") || (Regexp.match("^ +$", desc))) + desc = "This room does not have a description yet.\n"; + write("You are currently in " + pathobj->query_attribute("OBJ_NAME") + "\n" + desc + "\n"); -int take(string name) -{ - string fullpath=""; - fullpath = getpath()+"/"+name; - object orig_file = OBJ(fullpath); - if(orig_file) - { - object dup_file = orig_file->duplicate(); - dup_file->move(me); - write(name+" copied to your rucksack.\n"); + return 0; } - else - write("Please mention a file in this room."); + +int look(string | void str) { + if (str) { + return 0; + } + desc_room(); + list("files"); + write("---------------\n"); + list("containers"); + write("---------------\n"); + list("gates"); + write("---------------\n"); + list("rooms"); + write("---------------\n"); + return 0; } -int gothrough(string gatename) -{ +int take(string name) { string fullpath = ""; - fullpath = getpath()+"/"+gatename; - object gate = OBJ(fullpath); - if(gate) - { - object exit = gate->get_exit(); - string exit_path1 = "",exit_path2 = ""; -// exit_path1 = _Server->get_module("filepath:tree")->check_tilde(exit); -// exit_path2 = _Server->get_module("filepath:tree")->object_to_path(exit); -// if(exit_path1!="") -// goto_room(exit_path1); -// else if(exit_path2!="/void/"||exit_path2!="") -// goto_room(exit_path2); -// else -// write("Problem with object_to_path\n"); - exit_path1 = exit->query_attribute("OBJ_PATH"); //change to object_to_path - if(exit_path1!="") - goto_room(exit_path1); + fullpath = getpath() + "/" + name; + object orig_file = OBJ(fullpath); + if (orig_file) { + object dup_file = orig_file->duplicate(); + dup_file->move(me); + write(name + " copied to your rucksack.\n"); + } else + write("Please mention a file in this room."); + + return 0; } - else - write(gatename+" is not reachable from current room\n"); - return 0; -} -int delete(string file_cont_name) -{ - string fullpath=""; - fullpath = getpath()+"/"+file_cont_name; - if(OBJ(fullpath)) - return 0; - return 0; -} +int gothrough(string gatename) { + string fullpath = ""; + fullpath = getpath() + "/" + gatename; + object gate = OBJ(fullpath); + if (gate) { + object exit = gate->get_exit(); + string exit_path1 = "", exit_path2 = ""; + // exit_path1 = _Server->get_module("filepath:tree")->check_tilde(exit); + // exit_path2 = _Server->get_module("filepath:tree")->object_to_path(exit); + // if(exit_path1!="") + // goto_room(exit_path1); + // else if(exit_path2!="/void/"||exit_path2!="") + // goto_room(exit_path2); + // else + // write("Problem with object_to_path\n"); + exit_path1 = exit->query_attribute("OBJ_PATH"); //change to object_to_path + if (exit_path1 != "") + goto_room(exit_path1); + } else + write(gatename + " is not reachable from current room\n"); + + return 0; + } -int create_ob(string type,string name,string destination) -{ - string desc = readln->read("How would you describe it?\n"); - mapping data = ([]); - type = String.capitalize(type); - if(destination == ".") - destination = getpath(); - if(type=="Exit") - { - object exit_to = OBJ(readln->read("Where do you want to exit to?(full path)\n")); -// object exit_from = OBJ(getpath()); - data = ([ "exit_from":OBJ(destination), "exit_to":exit_to ]); - } - else if(type=="Link") - { - object link_to = OBJ(readln->read("Where does the link lead?\n")); - data = ([ "link_to":link_to ]); - } - object myobj = create_object(type,name,desc,data); -/* if(type=="Room" || type=="Container"){ - if(destination==".") - myobj->move(OBJ(getpath())); - else - myobj->move(OBJ(destination)); - } - */ - if(!(type == "Exit")) - myobj->move(OBJ(destination)); +int delete(string file_cont_name) { + string fullpath = ""; + fullpath = getpath() + "/" + file_cont_name; + if (OBJ(fullpath)) - return 0; -} + return 0; + return 0; + } -int peek(string container) -{ - string fullpath = ""; - fullpath = getpath()+"/"+container; - string pathfact = _Server->get_factory(OBJ(fullpath))->query_attribute("OBJ_NAME"); - if(pathfact=="Room.factory") - { - write("Maybe you are looking for the command 'look'\n"); - return 0; - } - if(pathfact!="Container.factory") - { - write("You can't peek into a "+pathfact[0..sizeof(pathfact)-8]+"\n"); - return 0; - } - array(string) conts = get_list("containers", fullpath); - array(string) files = get_list("files", fullpath); - write("You peek into "+container+"\n\n"); - display("containers", conts); - display("files", files); +int create_ob(string type, string name, string destination) { + string desc = readln->read("How would you describe it?\n"); + mapping data = ([]); + type = String.capitalize(type); + if (destination == ".") + destination = getpath(); + if (type == "Exit") { + object exit_to = OBJ(readln->read("Where do you want to exit to?(full path)\n")); + // object exit_from = OBJ(getpath()); + data = ([ "exit_from" : OBJ(destination), "exit_to" : exit_to ]); + } else if (type == "Link") { + object link_to = OBJ(readln->read("Where does the link lead?\n")); + data = ([ "link_to" : link_to ]); + } + object myobj = create_object(type, name, desc, data); + /* if(type=="Room" || type=="Container"){ + if(destination==".") + myobj->move(OBJ(getpath())); + else + myobj->move(OBJ(destination)); + } + */ + if (!(type == "Exit")) + myobj->move(OBJ(destination)); + + return 0; + } + +int peek(string container) { + string fullpath = ""; + fullpath = getpath() + "/" + container; + string pathfact = _Server->get_factory(OBJ(fullpath))->query_attribute("OBJ_NAME"); + if (pathfact == "Room.factory") { + write("Maybe you are looking for the command 'look'\n"); + return 0; + } + if (pathfact != "Container.factory") { + write("You can't peek into a " + pathfact[0..sizeof (pathfact) - 8] + "\n"); + + return 0; + } + array(string) conts = get_list("containers", fullpath); + array(string) files = get_list("files", fullpath); + write("You peek into " + container + "\n\n"); + display("containers", conts); + display("files", files); } -void display(string type, array(string) strs) -{ - if(sizeof(strs)==0) - write("There are no "+type+" here\n"); - else if(sizeof(strs)==1) - write("There is 1 "+type[0..sizeof(type)-2]+" here\n"); - else - write("There are "+sizeof(strs)+" "+type+" here\n"); - foreach(strs, string str) - { - write(str+" "); - } - write("\n-----------------------\n"); +void display(string type, array(string) strs) { + if (sizeof (strs) == 0) + write("There are no " + type + " here\n"); + else if (sizeof (strs) == 1) + write("There is 1 " + type[0..sizeof (type) - 2] + " here\n"); + + else + write("There are " + sizeof (strs) + " " + type + " here\n"); + foreach(strs, string str) { + + write(str + " "); + } + write("\n-----------------------\n"); } -int inventory() -{ - array(string) conts = get_list("containers", me); - array(string) files = get_list("files", me); - array(string) others = get_list("others", me); - write("You check your inventory\n"); - display("containers", conts); - display("files", files); - display("other files", others); +int inventory() { + + array(string) conts = get_list("containers", me); + array(string) files = get_list("files", me); + array(string) others = get_list("others", me); + write("You check your inventory\n"); + display("containers", conts); + display("files", files); + display("other files", others); } -int editfile(string...args) -{ - int size = sizeof(args); - if(size<1){ - write("Please provide a file name\n"); - return 0; - } - array(string) fullpatharr = allocate(size); - array(string) pathfactarr = allocate(size); - array(object) obj = allocate(size); - for(int j = 0;jget_factory(OBJ(fullpatharr[j]))->query_attribute("OBJ_NAME"); - - if(pathfactarr[j]!="Document.factory"){ - write("You can't edit a "+pathfactarr[j][0..sizeof(pathfactarr[j])-8]); - return 0; +int editfile(string...args) { + int size = sizeof (args); + if (size < 1) { + write("Please provide a file name\n"); + return 0; } - obj[j] = OBJ(fullpatharr[j]); - } + array(string) fullpatharr = allocate(size); + array(string) pathfactarr = allocate(size); + array(object) obj = allocate(size); + for (int j = 0; j < size; j++) { + fullpatharr[j] = getpath() + "/" + args[j]; + pathfactarr[j] = _Server->get_factory(OBJ(fullpatharr[j]))->query_attribute("OBJ_NAME"); + + if (pathfactarr[j] != "Document.factory") { + write("You can't edit a " + pathfactarr[j][0..sizeof (pathfactarr[j]) - 8]); + return 0; + } + obj[j] = OBJ(fullpatharr[j]); + } + + applaunch(obj, exitnow); - applaunch(obj,exitnow); - - return 0; + return 0; } -void exitnow() -{} +void exitnow() { +} -string getpath() -{ - return me->get_last_trail()->query_attribute("OBJ_PATH"); +string getpath() { + return me->get_last_trail()->query_attribute("OBJ_PATH"); } -constant stash_help_doc = #"This is a sTeam Advanced Shell. All the STASH commands work with normal pike commands. Tab completion is available for both STASH commands and pike commands.\n\n"; +constant stash_help_doc =#"This is a sTeam Advanced Shell. All the STASH commands work with normal pike commands. Tab completion is available for both STASH commands and pike commands.\n\n"; From 31de2647432ac525833325c7c3ce05615defbeb0 Mon Sep 17 00:00:00 2001 From: ajinkya007 Date: Mon, 30 May 2016 21:56:01 +0530 Subject: [PATCH 14/91] Added steam-shell.vim plugin --- tools/steam-shell.vim | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tools/steam-shell.vim diff --git a/tools/steam-shell.vim b/tools/steam-shell.vim new file mode 100644 index 0000000..5264363 --- /dev/null +++ b/tools/steam-shell.vim @@ -0,0 +1,7 @@ +command! Steam call Steamshell() + +function! Steamshell() + execute "tabnew | r! ~/Desktop/sTeamOrig/tools/steam-shell.pike". " ".@* + silent !clear +endfunction + From 6c0c6e69b18c158a11f178a5e4d8cab1f181d875 Mon Sep 17 00:00:00 2001 From: ajinkya007 Date: Tue, 31 May 2016 00:22:26 +0530 Subject: [PATCH 15/91] Add the utility to run an sTeam-shell command inside Vi editor. Added VisTeam.pike and changes in applauncher.pike and steam-shell.vim --- tools/VisTeam.pike | 142 +++++++++++++++++++++++++++++++++++++++++ tools/applauncher.pike | 4 +- tools/steam-shell.pike | 5 +- tools/steam-shell.vim | 15 ++++- 4 files changed, 160 insertions(+), 6 deletions(-) create mode 100755 tools/VisTeam.pike diff --git a/tools/VisTeam.pike b/tools/VisTeam.pike new file mode 100755 index 0000000..3d9bcc9 --- /dev/null +++ b/tools/VisTeam.pike @@ -0,0 +1,142 @@ +#!/usr/local/lib/steam/bin/steam + +/* Copyright (C) 2000-2004 Thomas Bopp, Thorsten Hampel, Ludger Merkens + * Copyright (C) 2003-2004 Martin Baehr + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: debug.pike.in,v 1.1 2009/09/28 14:19:52 nicke Exp $ + */ + +constant cvs_version = "$Id: edit.pike.in,v 1.0 2010/09/15 14:19:52 martin Exp $"; + +inherit "applauncher.pike"; +inherit "steam-shell.pike"; +//inherit "/usr/local/lib/steam/server/modules/groups.pike"; +object conn, handler; +mapping conn_options = ([]); +object _Server, user_obj, file; +array(object) myobj; + +int main(int argc, array(string) argv) { + + options = init(argv); + _Server = conn->SteamObj(0); + users = _Server->get_module("users"); + me = users->lookup(options->user); + all = assign(conn, _Server, users); + all = all + (([ + ])); + myobj = ({create_object("Document", "Command.pike", "Holds the commands which the user will type.")}); + return applaunch(myobj, demo); + +} + +mapping options = ([ ]); + +void ping(string host, string port, string user, string | void pw) { + call_out(ping, 10, host, port, user, pw); + mixed a = conn->send_command(14, 0); + if (a == "sTeam connection lost.") { + conn = ((program) "client_base.pike")(); + conn->close(); + if (conn->connect_server(host, port) && user != "guest") { + if (conn->send_command(14, 0) != "sTeam connection lost.") { + conn->login(user, pw, 1); + _Server = conn->SteamObj(0); + user_obj = _Server->get_module("users")->lookup(options->user); + array(object) filearr = ({file}); + update(filearr); + } + } + } +} + +mapping init(array argv) { + + array opt = Getopt.find_all_options(argv, aggregate( + ({"host", Getopt.HAS_ARG, ( + {"-h", "--host"})}), + ({"user", Getopt.HAS_ARG, ( + {"-u", "--user"})}), + ({"port", Getopt.HAS_ARG, ( + {"-p", "--port"})}), + )); + + foreach(opt, array option) { + options[option[0]] = option[1]; + } + if (!options->host) + options->host = "127.0.0.1"; + if (!options->user) + options->user = "root"; + if (!options->port) + options->port = 1900; + else + options->port = (int) options->port; + + options->file = argv[-1]; + + string server_path = "/usr/local/lib/steam"; + + master()->add_include_path(server_path + "/server/include"); + master()->add_program_path(server_path + "/server/"); + master()->add_program_path(server_path + "/server/modules/groups.pike"); + master()->add_program_path(server_path + "/conf/"); + master()->add_program_path(server_path + "/spm/"); + master()->add_program_path(server_path + "/server/net/coal/"); + + conn = ((program) "client_base.pike")(); + // groups_pgm = ((program)"groups.pike")(); + int start_time = time(); + + werror("Connecting to sTeam server...\n"); + while (!conn->connect_server(options->host, options->port)) { + if (time() - start_time > 120) { + throw (({" Couldn't connect to server. Please check steam.log for details! \n", backtrace()})); + } + werror("Failed to connect... still trying ... (server running ?)\n"); + sleep(10); + } + + if (lower_case(options->user) == "guest") { + ping(options->host, options->port, options->user); + return options; + } + + mixed err; + string pw; + int tries = 3; + //readln->set_echo( 0 ); + do { + pw = Input.read_password(sprintf("Password for %s@%s", options->user, + options->host), "steam"); + // pw ="steam"; + //pw=readln->read(sprintf("passwd for %s@%s: ", options->user, options->host)); + } while ((err = catch (conn->login(options->user, pw, 1))) && --tries); + //readln->set_echo( 1 ); + + if (err != 0) { + werror("Failed to log in!\nWrong Password!\n"); + exit(1); + } + ping(options->host, options->port, options->user, pw); + return options; +} + +void demo() { +} + + diff --git a/tools/applauncher.pike b/tools/applauncher.pike index b3d6200..f8c169e 100644 --- a/tools/applauncher.pike +++ b/tools/applauncher.pike @@ -172,7 +172,7 @@ array edit(array(object) objarr) if((enveditor=="VIM")||(enveditor=="vim")){ //full path to .vim files to be mentioned - comm="vim*-S*/usr/local/lib/steam/tools/watchforchanges.vim*-S*/usr/local/lib/steam/tools/golden_ratio.vim*-c*edit "+debugfilearr[0]+"|sp "+filenamearr[0]; + comm="vim*-S*/usr/local/lib/steam/tools/steam-shell.vim*/usr/local/lib/steam/tools/watchforchanges.vim*-S*/usr/local/lib/steam/tools/golden_ratio.vim*-c*edit "+debugfilearr[0]+"|sp "+filenamearr[0]; if(size>1) comm = add_file_name(comm,filenamearr[1..],debugfilearr[1..]); } @@ -184,7 +184,7 @@ array edit(array(object) objarr) comm=comm+"*--eval*(setq buffer-read-only t)*--eval*"+sprintf("(setq frame-title-format \"%s\")",objarr[0]->get_identifier()) +"*--eval*(windmove-up)*--eval*(enlarge-window 5)"; } else{ - comm="vi*-S*/usr/local/lib/steam/tools/watchforchanges.vim*-S*/usr/local/lib/steam/tools/golden_ratio.vim*-c*edit "+debugfilearr[0]+"|sp "+filenamearr[0]; + comm="vi*-S*/usr/local/lib/steam/tools/steam-shell.vim*/usr/local/lib/steam/tools/watchforchanges.vim*-S*/usr/local/lib/steam/tools/golden_ratio.vim*-c*edit "+debugfilearr[0]+"|sp "+filenamearr[0]; if(size>1) comm = add_file_name(comm,filenamearr[1..],debugfilearr[1..]); diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index bee19ec..04e9c83 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -208,13 +208,12 @@ int main(int argc, array(string) argv) { if (sizeof (argv) > 1) { string cmd = ""; - //write("\n %s %d",cmd , sizeof(argv)); - if (sizeof (argv) >= 3){ + if (sizeof (argv) >= 3){ for (int i = 1; i +"Press +"Now enter the command Steam +"It would prompt you to enter steam password. After this the output of the command shall be displayed in a the log buffer which would be opened in a new tab. function! Steamshell() - execute "tabnew | r! ~/Desktop/sTeamOrig/tools/steam-shell.pike". " ".@* +"tab sb 2 displays the contents of the buffer 2 in a new tab. +"In this case the buffer 2 stands for the log buffer. +"In future if a vim script is included the buffer number should be noted down for the log buffer using :ls and the below command should be modified to include the changes in it. +"The contents selected in the Vi visual mode are savied in the "* register. The contents of this register are appended as an argument to the command which is simulated using execute command. +"r! Execute {cmd} and insert its standard output below the cursor or the specified line. + execute "tab sb 2 | r! ~/Desktop/sTeamOrig/tools/steam-shell.pike". " ".@* silent !clear endfunction From 32a3c904a7827fad6bac73646b8c14b5480fe5cd Mon Sep 17 00:00:00 2001 From: Ajinkya Wavare Date: Tue, 31 May 2016 20:57:36 +0530 Subject: [PATCH 16/91] Update steam-shell.vim --- tools/steam-shell.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/steam-shell.vim b/tools/steam-shell.vim index e2a45f1..1a8e64f 100644 --- a/tools/steam-shell.vim +++ b/tools/steam-shell.vim @@ -14,7 +14,7 @@ function! Steamshell() "In future if a vim script is included the buffer number should be noted down for the log buffer using :ls and the below command should be modified to include the changes in it. "The contents selected in the Vi visual mode are savied in the "* register. The contents of this register are appended as an argument to the command which is simulated using execute command. "r! Execute {cmd} and insert its standard output below the cursor or the specified line. - execute "tab sb 2 | r! ~/Desktop/sTeamOrig/tools/steam-shell.pike". " ".@* + execute "tab sb 2 | r! /usr/local/lib/steam/tools/steam-shell.pike". " ".@* silent !clear endfunction From 5c62236c29e486004c5c7690b6b609e0bbc6ecbc Mon Sep 17 00:00:00 2001 From: ajinkya007 Date: Tue, 31 May 2016 22:37:53 +0530 Subject: [PATCH 17/91] Change the register used in the steam-shell.vim The :* register is supported by the Vim which has +clipboard enabled in it. Vim needs to be installed using vim-gnome --- tools/steam-shell.vim | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/steam-shell.vim b/tools/steam-shell.vim index 1a8e64f..59e8da5 100644 --- a/tools/steam-shell.vim +++ b/tools/steam-shell.vim @@ -3,8 +3,7 @@ "Function Usage "Enter the Vi insert mode (i) and type the commands "Enter the Vi visual mode(v). Select the command using the Vi Visual mode. -"Now type : . This would display :'<,'> -"Press +"Now type : y To yank the text "Now enter the command Steam "It would prompt you to enter steam password. After this the output of the command shall be displayed in a the log buffer which would be opened in a new tab. @@ -13,8 +12,8 @@ function! Steamshell() "In this case the buffer 2 stands for the log buffer. "In future if a vim script is included the buffer number should be noted down for the log buffer using :ls and the below command should be modified to include the changes in it. "The contents selected in the Vi visual mode are savied in the "* register. The contents of this register are appended as an argument to the command which is simulated using execute command. -"r! Execute {cmd} and insert its standard output below the cursor or the specified line. - execute "tab sb 2 | r! /usr/local/lib/steam/tools/steam-shell.pike". " ".@* +"r! Execute {cmd} and insert its standard output below the cursor or the specified line. + execute "tab sb 2 | r! ~/home/Desktop/sTeamAjinkya/tools/steam-shell.pike". " ".@0 silent !clear endfunction From 5f3d96ddb6b69105f03b54799c44335ae3fe2d08 Mon Sep 17 00:00:00 2001 From: ajinkya007 Date: Wed, 1 Jun 2016 02:46:51 +0530 Subject: [PATCH 18/91] Support for multiline commands has been added --- tools/steam-shell.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/steam-shell.vim b/tools/steam-shell.vim index 59e8da5..df31106 100644 --- a/tools/steam-shell.vim +++ b/tools/steam-shell.vim @@ -12,8 +12,9 @@ function! Steamshell() "In this case the buffer 2 stands for the log buffer. "In future if a vim script is included the buffer number should be noted down for the log buffer using :ls and the below command should be modified to include the changes in it. "The contents selected in the Vi visual mode are savied in the "* register. The contents of this register are appended as an argument to the command which is simulated using execute command. -"r! Execute {cmd} and insert its standard output below the cursor or the specified line. - execute "tab sb 2 | r! ~/home/Desktop/sTeamAjinkya/tools/steam-shell.pike". " ".@0 +"r! Execute {cmd} and insert its standard output below the cursor or the specified line. + let @0 = substitute(@0, '\n', " ", "g") + execute "tab sb 2 | r! /usr/local/lib/steam/tools/steam-shell.pike". " ".@0 silent !clear endfunction From 0eebccc10e71db68cfdff7022f56b133ccb30d8d Mon Sep 17 00:00:00 2001 From: ajinkya007 Date: Tue, 7 Jun 2016 02:49:24 +0530 Subject: [PATCH 19/91] Update the buffer variable and the addition of script in applauncher.pike --- tools/applauncher.pike | 4 ++-- tools/steam-shell.vim | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/applauncher.pike b/tools/applauncher.pike index f8c169e..ae50dba 100644 --- a/tools/applauncher.pike +++ b/tools/applauncher.pike @@ -172,7 +172,7 @@ array edit(array(object) objarr) if((enveditor=="VIM")||(enveditor=="vim")){ //full path to .vim files to be mentioned - comm="vim*-S*/usr/local/lib/steam/tools/steam-shell.vim*/usr/local/lib/steam/tools/watchforchanges.vim*-S*/usr/local/lib/steam/tools/golden_ratio.vim*-c*edit "+debugfilearr[0]+"|sp "+filenamearr[0]; + comm="vim*-S*/usr/local/lib/steam/tools/steam-shell.vim*-S*/usr/local/lib/steam/tools/watchforchanges.vim*-S*/usr/local/lib/steam/tools/golden_ratio.vim*-c*edit "+debugfilearr[0]+"|sp "+filenamearr[0]; if(size>1) comm = add_file_name(comm,filenamearr[1..],debugfilearr[1..]); } @@ -184,7 +184,7 @@ array edit(array(object) objarr) comm=comm+"*--eval*(setq buffer-read-only t)*--eval*"+sprintf("(setq frame-title-format \"%s\")",objarr[0]->get_identifier()) +"*--eval*(windmove-up)*--eval*(enlarge-window 5)"; } else{ - comm="vi*-S*/usr/local/lib/steam/tools/steam-shell.vim*/usr/local/lib/steam/tools/watchforchanges.vim*-S*/usr/local/lib/steam/tools/golden_ratio.vim*-c*edit "+debugfilearr[0]+"|sp "+filenamearr[0]; + comm="vi*-S*/usr/local/lib/steam/tools/steam-shell.vim*-S*/usr/local/lib/steam/tools/watchforchanges.vim*-S*/usr/local/lib/steam/tools/golden_ratio.vim*-c*edit "+debugfilearr[0]+"|sp "+filenamearr[0]; if(size>1) comm = add_file_name(comm,filenamearr[1..],debugfilearr[1..]); diff --git a/tools/steam-shell.vim b/tools/steam-shell.vim index df31106..2b4a9a0 100644 --- a/tools/steam-shell.vim +++ b/tools/steam-shell.vim @@ -14,7 +14,7 @@ function! Steamshell() "The contents selected in the Vi visual mode are savied in the "* register. The contents of this register are appended as an argument to the command which is simulated using execute command. "r! Execute {cmd} and insert its standard output below the cursor or the specified line. let @0 = substitute(@0, '\n', " ", "g") - execute "tab sb 2 | r! /usr/local/lib/steam/tools/steam-shell.pike". " ".@0 + execute "tab sb 1 | r! /usr/local/lib/steam/tools/steam-shell.pike". " ".@0 silent !clear endfunction From 203aad8e0f7e0db2966430e5e7cc49cc26743377 Mon Sep 17 00:00:00 2001 From: Siddhant Date: Tue, 7 Jun 2016 20:18:25 +0530 Subject: [PATCH 20/91] Changes to add the TLS layer. There are bugs that need to be fixed in this comit --- .gitignore | 1 + server/client_base.pike | 616 +++++++++++++++++++++++++++++++++++++ server/kernel/sockets.pike | 340 ++++++++++++++++++++ spm/client_base.pike | 2 +- tools/steam-shell.pike | 16 +- 5 files changed, 967 insertions(+), 8 deletions(-) create mode 100644 server/client_base.pike create mode 100644 server/kernel/sockets.pike diff --git a/.gitignore b/.gitignore index a18f25e..bf04e45 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /bin/steam *.so *.o +help diff --git a/server/client_base.pike b/server/client_base.pike new file mode 100644 index 0000000..5e0f8c7 --- /dev/null +++ b/server/client_base.pike @@ -0,0 +1,616 @@ +/* Copyright (C) 2000-2005 Thomas Bopp, Thorsten Hampel, Ludger Merkens + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: client_base.pike,v 1.2 2008/07/17 16:45:00 astra Exp $ + */ + +constant cvs_version="$Id: client_base.pike,v 1.2 2008/07/17 16:45:00 astra Exp $"; + +inherit "kernel/sockets"; +inherit "net/coal/binary"; + +#include +#include +#include +#include + +#undef CLIENT_DEBUG + +#ifdef CLIENT_DEBUG +#define DEBUG_CLIENT(s, args...) werror(s+"\n", args) +#else +#define DEBUG_CLIENT(s, args...) +#endif + +private static mapping mObjects; // objects +private static string sLastPacket; // last package while communicating +private static int iOID; // the object id of the current object +private static int iTID; // the current transaction id +private static int iWaitTID; + static mapping mVariables; // session variables + static array aEvents; + static int __connected; + static int __downloadBytes; + int __last_response; + static function downloadStore; + static mapping mEvents; + +private static mixed miResult; +private static int miCommand; + +static Thread.Mutex cmd_mutex = Thread.Mutex(); +static Thread.Condition cmd_cond = Thread.Condition(); +static Thread.Queue resultQueue = Thread.Queue(); +static Thread.Queue cmdQueue = Thread.Queue(); +static object cmd_lock; + +string connected_server; +int connected_port; + + +class SteamObj +{ + private static int oID; + private static string identifier = 0; + private static int cl = 0; + private static int(0..1) nowait; + private static mapping(string:function) functions=([]); + + int get_object_id() { + return oID; + } + + int get_object_class() { + if ( cl == 0 ) { + int wid = iWaitTID; + int id = set_object(oID); + mixed res = send_command(COAL_COMMAND, ({ "get_object_class" })); + if ( intp(res) ) + cl = res; + set_object(id); + iWaitTID = wid; + } + return cl; + } + + object get_environment() { + return send_command(COAL_COMMAND, ({ "get_environment" })); + } + + string get_identifier() { + if ( !stringp(identifier) ) { + int wid = iWaitTID; + int id = set_object(oID); + identifier = send_command(COAL_COMMAND, ({ "get_identifier" })); + set_object(id); + iWaitTID = wid; + } + return identifier; + } + + void create(int id) { + oID = id; + } + + int status() { + return 1; // PSTAT_SAVE_OK + } + + int no_wait(void|int(0..1) _nowait) + { + if(!zero_type(_nowait) && nowait == !_nowait) + { + nowait=!!_nowait; + return !nowait; + } + else + return nowait; + } + + string function_name(function fun) + { + return search(functions, fun); + } + + string _sprintf() + { + return "OBJ#"+oID; + string describe=""; + catch{ describe=`->("describe")(); }; + return sprintf("%s:%d/%s", connected_server, connected_port, describe); + } + + function `->(string fun) + { + if(::`->(fun)) + return ::`->(fun); + else + { + if(fun == "exec_code") + return 0; + else if (fun=="serialize_coal") + return 0; + if(!functions->fun) + functions[fun]=lambda(mixed|void ... args) { + return send_cmd(oID, fun, args, nowait); + }; + return functions[fun]; + } + } + + function find_function(string fun) + { + if(!functions->fun) + functions[fun]=lambda(mixed|void ... args) { + return send_cmd(oID, fun, args, nowait); + }; + return functions[fun]; + } +}; + + +/** + * + * + * @param + * @return + * @author Thomas Bopp) + * @see + */ +int set_object(int|object|string id) +{ + int oldID = iOID; + + if ( stringp(id) ) { + if ( objectp(mVariables[id]) ) + iOID = mVariables[id]->get_object_id(); + else + iOID = mVariables[id]; + } + else if ( objectp(id) ) + iOID = id->get_object_id(); + else + iOID = id; + return oldID; +} + +/** + * + * + * @param + * @return + * @author Thomas Bopp (astra@upb.de) + * @see + */ +static object find_obj(int|string id) +{ + int oid; + if ( stringp(id) ) { + object fp = send_cmd( 0, "get_module", "filepath:tree" ); + object obj = send_cmd( fp, "path_to_object", id ); + if ( !objectp(obj) ) return 0; + oid = obj->get_object_id(); + } + else oid = id; + + if ( !mObjects[oid] ) { + mObjects[oid] = SteamObj(oid); + //werror("Created:"+master()->describe_object(mObjects[id])+"\n"); + } + return mObjects[oid]; +} + +object find_object(int|string id) { return find_obj(id); } + +mixed get_variable(string key) +{ + return mVariables[key]; +} + +/** + * + * + * @param + * @return + * @author Thomas Bopp (astra@upb.de) + * @see + */ +int connect_server(string server, int port) +{ + iTID = 1; + iOID = 0; + sLastPacket = ""; + __downloadBytes = 0; + mVariables = ([ ]); + mObjects = ([ ]); + aEvents = ({ }); + mEvents = ([ ]); + + sock->open_socket(); + sock->set_blocking(); + if ( sock->connect(server, port) ) { + SSL.sslfile(sock,SSL.context(),1,1); + werror("here"); + MESSAGE("Connected to " + server + ":"+port +"\n"); + connected_server=server; + connected_port=port; + __last_response = time(); // timestamp of last response + __connected = 1; + sock->set_buffer(65536, "r"); + sock->set_buffer(65536, "w"); + set_blocking(); + thread_create(read_thread); + thread_create(handle_commands); + return 1; + } + return 0; +} + +void create() +{ +} + +static int write(string str) +{ + __last_response = time(); + return ::write(str); +} + +static void handle_command(string func, mixed args) { } + +void handle_commands() +{ + mixed res; + while ( res = cmdQueue->read() ) { + if ( arrayp(res) ) { + if ( arrayp(res[1]) ) { + mixed err = catch { + handle_command(res[1][0], res[1][1]); + }; + if ( err != 0 ) + werror("Fatal error while calling command: %O\n%O", err[0], err[1]); + } + } + } +} + + +void read_callback(object id, string data) +{ + __last_response = time(); + + if ( functionp(downloadStore) ) { + mixed err = catch { + downloadStore(data); + }; + __downloadBytes -= strlen(data); + if ( __downloadBytes <= 0 ) { + downloadStore(0); + downloadStore = 0; // download finished + } + return; + } + sLastPacket += data; + if ( __downloadBytes > 0 ) { + if ( __downloadBytes <= strlen(sLastPacket) ) + resultQueue->write(sLastPacket); + return; + } + mixed res; + res = receive_binary(sLastPacket); + while ( arrayp(res) ) { + int tid = res[0][0]; + int cmd = res[0][1]; + + if ( cmd == COAL_EVENT ) { + DEBUG_CLIENT("Event %O", res[1]); + } + DEBUG_CLIENT("RCVD Package(%d): Waiting for %d\n", tid, iWaitTID); + sLastPacket = res[2]; + if ( tid == iWaitTID ) { + miResult = res[1]; + miCommand = res[0][1]; + resultQueue->write(miResult); + } + else if ( cmd == COAL_COMMAND ) { + cmdQueue->write(res); + } + res = receive_binary(sLastPacket); + } +} + +string download(int bytes, void|function store) +{ + // actually the last command should have been the upload response, + // so there shouldnt be anything on the line except events + // which should have been already processed + // everything else should be download data + string data; + __downloadBytes = bytes; + + if ( functionp(store) ) { + data = copy_value(sLastPacket[..bytes]); + __downloadBytes -= strlen(data); + if ( strlen(data) > 0 ) + store(data); + if ( __downloadBytes <= 0 ) { + store(0); + return ""; + } + downloadStore = store; + return ""; + } + downloadStore = 0; + + if ( strlen(sLastPacket) >= bytes ) { + data = copy_value(sLastPacket[..bytes]); + if ( bytes > strlen(sLastPacket) ) + sLastPacket = sLastPacket[bytes+1..]; + else + sLastPacket = ""; + __downloadBytes = 0; + return data; + } + + miResult = resultQueue->read(); + data = copy_value(sLastPacket[..bytes]); + if ( strlen(sLastPacket) > bytes ) + sLastPacket = sLastPacket[bytes+1..]; + else + sLastPacket = ""; + __downloadBytes = 0; + return data; +} + +/** + * + * + * @param + * @return + * @author Thomas Bopp) + * @see + */ +void handle_error(mixed err) +{ + throw(err); +} + +/** + * + * + * @param + * @return + * @author Thomas Bopp (astra@upb.de) + * @see + */ +mixed send_command(int cmd, array(mixed) args, int|void no_wait) +{ + if ( !no_wait ) iWaitTID = iTID; + aEvents = ({ }); + + + string msg = coal_compose(iTID++, cmd, iOID, 0, args); + string nmsg = copy_value(msg); + + send_message(nmsg); + if ( no_wait ) return 0; + + mixed result = resultQueue->read(); + if ( miCommand == COAL_ERROR ) { + handle_error(result); + } + return result; +} + +void subscribe_event(object obj, int eid, function callback) +{ + int oid = set_object(obj); + send_command(COAL_SUBSCRIBE, ({ eid }) ); + mEvents[eid] = callback; + set_object(oid); +} + +mixed send_cmd(object|int obj, string func, mixed|void args, void|int no_wait) +{ + int oid = set_object(obj); + if ( zero_type(args) ) + args = ({ }); + else if ( !arrayp(args) ) + args = ({ args }); + mixed res = send_command(COAL_COMMAND, ({ func, args }), no_wait); + set_object(oid); + return res; +} + +mixed +login(string name, string pw, int features, string|void cname, int|void novars) +{ + if ( !stringp(cname) ) + cname = "steam-pike"; + + mixed loginData; + if ( features != 0 ) + loginData =send_command(COAL_LOGIN, ({ name, pw, cname, features, __id })); + else + loginData = + send_command(COAL_LOGIN,({ name, pw, cname,CLIENT_FEATURES_ALL, __id})); + + if ( arrayp(loginData) && sizeof(loginData) >= 9 ) { + mVariables["user"] = iOID; + foreach ( indices(loginData[8]), string key ) { + mVariables[key] = loginData[8][key]; + } + mVariables["rootroom"] = loginData[6]; + sLastPacket = ""; + if ( novars != 1 ) { + foreach ( values(loginData[9]), object cl ) { + set_object(cl->get_object_id()); + mVariables[send_cmd(cl,"get_identifier")] = cl; + } + } + return name; + } + return 0; +} + +mixed logout() +{ + __connected = 0; + write(coal_compose(0, COAL_LOGOUT, 0, 0, 0)); +} + + +void was_closed() +{ + resultQueue->write(""); + ::was_closed(); +} + + +void write_error2file(mixed|string err, int recursive) { + + Stdio.File error_file; + string path; + array(string) directory; + int file_counter =0; + int found=0; + path = getcwd(); + directory = get_dir(path); + while (found==0){ + int tmp_found=1; + tmp_found=Stdio.exist(path+"/install_error."+file_counter); + if (tmp_found==1){ + file_counter = file_counter + 1; + } + else{ + found = 1; + } + } + + if (recursive==1) + file_counter = file_counter -1; + error_file=Stdio.File (path+"/install_error."+file_counter ,"cwa"); + if (stringp (err)){ + error_file->write(err); + } + if(arrayp(err)){ + foreach(err, mixed error){ + if ( stringp(error) || intp(error) ) + error_file->write((string)error); + else if ( objectp(error) ) + error_file->write("\n"); + else if ( arrayp(error) ){ + write_error2file(error,1); + } + } + } + if (recursive!=0) + error_file->close(); +} + + +/** + * Creates a new document object on the server. + * + * @param name the name of the new object + * @param where the container or room in which to create the new object + * @param mimetype (optional) the mime type of the new object (if not + * specified, the mime type will be determined by the object name) + * @param content (optional) the content for the new object (if not specified, + * the new object will not have any content) + * @return the newly created object (if an error occurs, an exception will be + * thrown instead) + */ +object create_document ( string name, object where, void|string mimetype, void|string content ) +{ + if ( !stringp(name) || sizeof(name) < 1 ) + throw( ({ "No name specified !" }) ); + if ( !objectp(where) ) + throw( ({ "No room or container specified !" }) ); + object obj = send_cmd( where, "get_object_byname", name ); + if ( objectp(obj) ) + throw( ({ "Object \""+name+"\" already found !" }) ); + object factory = send_cmd( 0, "get_factory", CLASS_DOCUMENT ); + if ( !objectp(factory) ) + throw( ({ "Document factory not found on server !" }) ); + mapping params = ([ "name":name ]); + if ( stringp(mimetype) && sizeof(mimetype) > 0 ) + params["mimetype"] = mimetype; + obj = send_cmd( factory, "execute", params ); + if ( !objectp(obj) ) + throw( ({ "Could not create document !" }) ); + send_cmd( obj, "move", where ); + + if ( stringp(content) ) + send_cmd( obj, "set_content", content ); + + return obj; +} + + +/** + * Creates a new room object on the server. + * + * @param name the name of the new object + * @param where the room in which to create the new object + * @return the newly created object (if an error occurs, an exception will be + * thrown instead) + */ +object create_room ( string name, object where ) +{ + if ( !stringp(name) || sizeof(name) < 1 ) + throw( ({ "No name specified !" }) ); + if ( !objectp(where) ) + throw( ({ "No room specified !" }) ); + object obj = send_cmd( where, "get_object_byname", name ); + if ( objectp(obj) ) + throw( ({ "Object \""+name+"\" already found !" }) ); + object factory = send_cmd( 0, "get_factory", CLASS_ROOM ); + if ( !objectp(factory) ) + throw( ({ "Room factory not found on server !" }) ); + obj = send_cmd( factory, "execute", ([ "name":name ]) ); + if ( !objectp(obj) ) + throw( ({ "Could not create room !" }) ); + send_cmd( obj, "move", where ); + return obj; +} + +/** + * Creates a new container object on the server. + * + * @param name the name of the new object + * @param where the container or room in which to create the new object + * @return the newly created object (if an error occurs, an exception will be + * thrown instead) + */ +object create_container ( string name, object where ) +{ + if ( !stringp(name) || sizeof(name) < 1 ) + throw( ({ "No name specified !" }) ); + if ( !objectp(where) ) + throw( ({ "No room or container specified !" }) ); + object obj = send_cmd( where, "get_object_byname", name ); + if ( objectp(obj) ) + throw( ({ "Object \""+name+"\" already found !" }) ); + object factory = send_cmd( 0, "get_factory", CLASS_CONTAINER ); + if ( !objectp(factory) ) + throw( ({ "Container factory not found on server !" }) ); + obj = send_cmd( factory, "execute", ([ "name":name ]) ); + if ( !objectp(obj) ) + throw( ({ "Could not create container !" }) ); + send_cmd( obj, "move", where ); + return obj; +} diff --git a/server/kernel/sockets.pike b/server/kernel/sockets.pike new file mode 100644 index 0000000..8420d78 --- /dev/null +++ b/server/kernel/sockets.pike @@ -0,0 +1,340 @@ +/* Copyright (C) 2000-2004 Thomas Bopp, Thorsten Hampel, Ludger Merkens + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: socket.pike,v 1.2 2009/08/04 16:28:01 nicke Exp $ + */ + +constant cvs_version="$Id: socket.pike,v 1.2 2009/08/04 16:28:01 nicke Exp $"; + +inherit SSL.sslfile : socket; + +#include +#include +#include +#include + +Stdio.File sock = Stdio.File(); + +private static string __buffer; +private static int __len; +private static function fWriteFunction; +private static function fFinishFunction; + +#ifdef THREAD_READ +private static Thread.Condition write_cond = Thread.Condition(); +private static Thread.Mutex read_mutex = Thread.Mutex(); +private static Thread.Queue msgQueue = Thread.Queue(); +private static Thread.Queue closeQueue = Thread.Queue(); +#endif + +#ifdef SOCKET_DEBUG +#define DEBUG(s) werror("["+__id+"] "+s+"\n") +#else +#define DEBUG(s) +#endif + +#define ISCLOSED (closeQueue->size() > 0) + +int __id; + +/** + * + * + * @param + * @return + * @author Thomas Bopp + * @see + */ +static void +disconnect() +{ + DEBUG("DISCONNECT()\n"); + mixed err = catch { + ::close(); + sock->close(); + }; + if ( err != 0 ) + DEBUG("While disconnecting socket:\n"+sprintf("%O",err)); + if ( objectp(read_mutex) ) + destruct(read_mutex); +} + +/** + * send a message to the client + * + * @param str - the message to send + * @author Thomas Bopp + * @see write_callback + */ +static void send_message(string str) +{ + DEBUG("send_message("+strlen(str)+" bytes...)"); + msgQueue->write(str); +} + +/** + * this function is called when there is free space for writting + * + * @author Thomas Bopp (astra@upb.de) + * @see read_callback + * @see register_send_function + * @see send_message + */ +static void write_callback(string __buffer) +{ + int written; + mixed w; + int len; + + DEBUG("write_callback("+strlen(__buffer)+ + ", closed?"+(ISCLOSED?"true":"false")); + + + if ( ISCLOSED ) return; + + len = strlen(__buffer); + + if ( functionp(fWriteFunction) ) { + w = fWriteFunction(__len); + + if ( !stringp(w) ) { + fFinishFunction(); + fWriteFunction = 0; + fFinishFunction = 0; + } + else { + __len += strlen(w); + msgQueue->write(w); + } + } + while ( strlen(__buffer) > 0 ) { + mixed err = catch { + written = write(__buffer); + DEBUG("written " + written + " bytes..."); + }; + if ( err != 0 ) { + __buffer = ""; + DEBUG("error while writting:\n"+sprintf("%O\n",err)); + return; + } + + if ( written < 0 ) { + return; + } + if ( written < strlen(__buffer ) ) { + if ( written > 0 ) + __buffer = __buffer[written..]; + else if ( written == 0 ) + sleep(0.1); + } + else + return; + } +} + +/** + * this function is called when data is received on the socket + * + * @param id - data for the socket + * @param data - the arriving data + * @author Thomas Bopp + * @see write_callback + */ +static void read_callback(mixed id, string data) +{ +} + +static void was_closed() +{ + closeQueue->write(""); +} + +/** + * The read thread reads data. + * + * @param + * @return + * @author Thomas Bopp (astra@upb.de) + * @see + */ +final static void tread_data() +{ + string str; + + if ( ISCLOSED ) return; + + mixed err = catch { + str = socket::read(SOCKET_READ_SIZE, 1); + }; + DEBUG("Returning from read...\n"); + + if ( err != 0 || !stringp(str) || strlen(str) == 0 ) { + DEBUG("Socket was closed while in read..."); + was_closed(); + } + else { + DEBUG("Reading " + strlen(str) + " bytes...\n"); + read_callback(0, str); + } +} + +/** + * close the connection to the client + * + * @author Thomas Bopp + */ +void +close_connection() +{ + DEBUG("close_connection()"); + closeQueue->write(""); + msgQueue->write(""); + + mixed err = catch { + socket::set_read_callback(0); + }; +} + +/** + * create the object (the constructor) + * + * @param f - the portobject + * @author Thomas Bopp + */ +static void create(object f) +{ + sock->assign(f); + SSL.sslfile(sock,SSL.context(),1,1); +// socket::assign(f); + __buffer = ""; + fWriteFunction = 0; + socket::set_blocking(); + sock->set_buffer(65536*10, "w"); + sock->set_buffer(65536*10, "r"); + thread_create(read_thread); +} + +/** + * Get the ip of this socket. + * + * @return the ip number 127.0.0.0 + * @author Thomas Bopp) + */ +string|int get_ip() +{ + mixed err; + string addr; + + err = catch { + addr = query_address(); + }; + if ( err != 0 ) + addr = "no connected"; + LOG("query_adress() returns " + addr); + string ip = 0; + if ( stringp(addr) ) + sscanf(addr, "%s %*d", ip); + return ip; +} + + +/** + * register a callback function for writting data to the socket + * if there is already a function defined there will be a runtime error + * + * @param f - the callback function + * @author Thomas Bopp (astra@upb.de) + * @see write_callback + */ +static void register_send_function(function f, function e) +{ + ASSERTINFO(!functionp(fWriteFunction), + "Allready defined writer function !"); + + string w = f(0); + if ( !stringp(w) ) + return; + + fWriteFunction = f; + fFinishFunction = e; + __len = strlen(w); + msgQueue->write(w); +} + + +#ifdef THREAD_READ + +/** + * The main function for the reader thread. Calls tread_data() repeatedly. + * + * @author Thomas Bopp (astra@upb.de) + * @see tread_data + */ +final static void read_thread() +{ + DEBUG("read_thread() created, now creating write_thread()..."); + + thread_create(write_thread); + while ( !ISCLOSED ) { + DEBUG("!ISCLOSED and reading data...."); + tread_data(); + } + DEBUG("Read Thread Ended...."); + closeQueue->write(""); + DEBUG("Read Thread Ended....: CloseQueue="+closeQueue->size()); + msgQueue->write("end"); +} + + +/** + * The main function for the writer thread. Calls the write_callback() + * repeatedly and waits for signals. + * + * @param + * @return + * @author Thomas Bopp (astra@upb.de) + * @see + */ +final static void +write_thread() +{ + string msg; + DEBUG("write_thread() created ..."); + while ( !ISCLOSED && (msg = msgQueue->read()) ) { + write_callback(msg); + } + DEBUG("disconnecting socket...: CloseQueue="+closeQueue->size()); + + disconnect(); + closeQueue->write(""); +} +#endif + +string describe() +{ + return "Socket("+__id+", closed="+closeQueue->size()+","+get_ip()+")"; +} + +void set_id(int i) { __id = i; } +int get_id() { return __id; } +bool is_closed() { return closeQueue->size() >= 2; } +int is_closed_num() { return closeQueue->size(); } +string get_identifier() { return "socket"; } + + + + + diff --git a/spm/client_base.pike b/spm/client_base.pike index b885514..0ba419b 100755 --- a/spm/client_base.pike +++ b/spm/client_base.pike @@ -19,7 +19,7 @@ constant cvs_version="$Id: client_base.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $"; -inherit "kernel/socket"; +inherit "kernel/sockets"; inherit "net/coal/binary"; #include diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index af55da8..ce93819 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -157,12 +157,15 @@ void ping() { call_out(ping, 10); mixed a = conn->send_command(14, 0); + + if(a=="sTeam connection lost.") { flag = 0; readln->set_prompt(getpath()+"~ "); - conn = ((program)"client_base.pike")(); - conn->close(); + // conn = ((program)"client_base.pike")(); + conn = ((program)compile_file("../server/client_base.pike"))(); + conn->close(); if(conn->connect_server(options->host, options->port)) { remove_call_out(ping); @@ -247,7 +250,6 @@ int main(int argc, array(string) argv) if(result!=0) { - write(result[0]); write("Wrong command.||maybe some bug.\n"); } } @@ -289,7 +291,7 @@ mapping init(array argv) if(!options->user) options->user="root"; if(!options->port) - options->port=1900; + options->port=1999; else options->port=(int)options->port; @@ -301,8 +303,8 @@ mapping init(array argv) master()->add_program_path(server_path+"/spm/"); master()->add_program_path(server_path+"/server/net/coal/"); - conn = ((program)"client_base.pike")(); - +// conn = ((program)"client_base.pike")(); + conn = ((program)compile_file("../server/client_base.pike"))(); int start_time = time(); werror("Connecting to sTeam server...\n"); @@ -315,8 +317,8 @@ mapping init(array argv) werror("Failed to connect... still trying ... (server running ?)\n"); sleep(10); } - ping(); + if(lower_case(options->user) == "guest") return options; From 66a2f6dff4d5fa41807e4aebf29fbdd4737288fc Mon Sep 17 00:00:00 2001 From: Siddhant Date: Tue, 7 Jun 2016 22:51:14 +0530 Subject: [PATCH 21/91] Fixes the bugs in the previous commit and gives a working ssl connection. --- server/client_base.pike | 3 +-- server/kernel/sockets.pike | 4 ++++ spm/client_base.pike | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/server/client_base.pike b/server/client_base.pike index 5e0f8c7..4fc66b6 100644 --- a/server/client_base.pike +++ b/server/client_base.pike @@ -242,8 +242,7 @@ int connect_server(string server, int port) sock->open_socket(); sock->set_blocking(); if ( sock->connect(server, port) ) { - SSL.sslfile(sock,SSL.context(),1,1); - werror("here"); + connect_ssl(sock); MESSAGE("Connected to " + server + ":"+port +"\n"); connected_server=server; connected_port=port; diff --git a/server/kernel/sockets.pike b/server/kernel/sockets.pike index 8420d78..3254372 100644 --- a/server/kernel/sockets.pike +++ b/server/kernel/sockets.pike @@ -50,6 +50,10 @@ private static Thread.Queue closeQueue = Thread.Queue(); int __id; +void connect_ssl(object sock_file){ + ::create(sock_file,SSL.context(),1,1); +} + /** * * diff --git a/spm/client_base.pike b/spm/client_base.pike index 0ba419b..b885514 100755 --- a/spm/client_base.pike +++ b/spm/client_base.pike @@ -19,7 +19,7 @@ constant cvs_version="$Id: client_base.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $"; -inherit "kernel/sockets"; +inherit "kernel/socket"; inherit "net/coal/binary"; #include From 4a4323299ad94249a86038c0ef0bd403bc283223 Mon Sep 17 00:00:00 2001 From: Siddhant Date: Wed, 8 Jun 2016 17:40:03 +0530 Subject: [PATCH 22/91] small improvements. --- server/client_base.pike | 2 +- server/kernel/sockets.pike | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/client_base.pike b/server/client_base.pike index 4fc66b6..f97b7fd 100644 --- a/server/client_base.pike +++ b/server/client_base.pike @@ -242,7 +242,7 @@ int connect_server(string server, int port) sock->open_socket(); sock->set_blocking(); if ( sock->connect(server, port) ) { - connect_ssl(sock); + connect_ssl(); MESSAGE("Connected to " + server + ":"+port +"\n"); connected_server=server; connected_port=port; diff --git a/server/kernel/sockets.pike b/server/kernel/sockets.pike index 3254372..bb0c0ed 100644 --- a/server/kernel/sockets.pike +++ b/server/kernel/sockets.pike @@ -50,8 +50,8 @@ private static Thread.Queue closeQueue = Thread.Queue(); int __id; -void connect_ssl(object sock_file){ - ::create(sock_file,SSL.context(),1,1); +void connect_ssl(){ + ::create(sock,SSL.context(),1,1); } /** From cf3dbc001a4aeede2f6ac625006879b38ba4758d Mon Sep 17 00:00:00 2001 From: Siddhant Date: Thu, 9 Jun 2016 15:35:54 +0530 Subject: [PATCH 23/91] Fixed the logs when opened via edit.pike --- .gitignore | 1 + tools/applauncher.pike | 4 +++- tools/edit.pike | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a18f25e..bf04e45 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /bin/steam *.so *.o +help diff --git a/tools/applauncher.pike b/tools/applauncher.pike index 43a6664..5bf4a9f 100644 --- a/tools/applauncher.pike +++ b/tools/applauncher.pike @@ -30,6 +30,7 @@ int set=0; string dir; array(string) debugfilearr; array(string) olderrorsarr; +int exitcall=0; void upload(object editor, array(string) filearr ,array(int) last_mtimearr, array(object) objarr, array(object) xslobjarr, function|void exit_callback) { @@ -238,7 +239,8 @@ int applaunch(array(object) objarr,function exit_callback) olderrorsarr = allocate(size); call_out(upload, 1, editor, filearr, filestatarr, objarr, xslobjarr, exit_callback); - editor.wait(); + if(exitcall==0) //exitcall = 0 means it is called by steam-shell otherwise by edit.pike + editor.wait(); // signal(signum("SIGINT"), prompt); diff --git a/tools/edit.pike b/tools/edit.pike index bf3bbe3..c4ef91c 100755 --- a/tools/edit.pike +++ b/tools/edit.pike @@ -82,6 +82,7 @@ int main(int argc, array(string) argv) // array(string) gps = ({ "Admin" , "coder" , "help" , "PrivGroups" , "WikiGroups" , "sTeam" }); get_file_object(); array(object) filearr = ({file}); + exitcall=1; return applaunch(filearr,demo); } From 934dccc6a301c5de2d9293f36e6bf9238b0d3303 Mon Sep 17 00:00:00 2001 From: ajinkya007 Date: Mon, 13 Jun 2016 15:08:43 +0530 Subject: [PATCH 24/91] Add support for special character's to be entered to the steam-shell as arguments --- tools/steam-shell.pike | 3 ++- tools/steam-shell.vim | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index 04e9c83..d25189a 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -205,7 +205,8 @@ int main(int argc, array(string) argv) { handler->add_input_line("start backend"); string command; // Regexp.SimpleRegexp a = Regexp.SimpleRegexp("[a-zA-Z]* [\"|'][a-zA-Z _-]*[\"|']"); - + // To run commands from the steam-shell.pike by passing them as argument to the script, note that the special characters which have been entered in the bash shell. In order to escape the special characters, pass them through the ''. The character's would lose their special meaning. + // eg: ./steam-shell.pike '_Server->get_module("users")->get_users();' if (sizeof (argv) > 1) { string cmd = ""; if (sizeof (argv) >= 3){ diff --git a/tools/steam-shell.vim b/tools/steam-shell.vim index 2b4a9a0..bd9945b 100644 --- a/tools/steam-shell.vim +++ b/tools/steam-shell.vim @@ -14,7 +14,7 @@ function! Steamshell() "The contents selected in the Vi visual mode are savied in the "* register. The contents of this register are appended as an argument to the command which is simulated using execute command. "r! Execute {cmd} and insert its standard output below the cursor or the specified line. let @0 = substitute(@0, '\n', " ", "g") - execute "tab sb 1 | r! /usr/local/lib/steam/tools/steam-shell.pike". " ".@0 + execute "tab sb 1 | r! /usr/local/lib/steam/tools/steam-shell.pike". " '".@0."'" silent !clear endfunction From bdb516183cc6942872bd42c1a7394989f30b5959 Mon Sep 17 00:00:00 2001 From: Siddhant Date: Wed, 15 Jun 2016 16:14:08 +0530 Subject: [PATCH 25/91] We are able to open files from inside vim using :Open . Log needs to be fixed --- tools/steam-shell.vim | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tools/steam-shell.vim b/tools/steam-shell.vim index bd9945b..9a19414 100644 --- a/tools/steam-shell.vim +++ b/tools/steam-shell.vim @@ -1,4 +1,7 @@ -command! Steam call Steamshell() +command! Steam call Steamshell() +command! -nargs=1 Open call Open() +command! Upload call Upload() +autocmd BufWritePost * Upload "Note: This file needs to be included in the applauncher.pike in the function call edit(array(object)) "Function Usage "Enter the Vi insert mode (i) and type the commands @@ -18,3 +21,23 @@ function! Steamshell() silent !clear endfunction +function! Open(name) + let code = 'string open(){string fullpath="'.a:name.'";string pathfact=_Server->get_factory(OBJ(fullpath))->query_attribute("OBJ_NAME");if (pathfact \!= "Document.factory") {write("you can not edit this file.");return 0;}Object obj = OBJ(fullpath);string content = obj->get_content();string dir;dir="/tmp/"+(MIME.encode_base64(Crypto.Random.random_string(10), 1)-("/"))+System.getpid();mkdir(dir,0700);string filename=obj->get_object_id()+"-"+obj->get_identifier();filename=dir+"/"+filename;string debugfilename=filename+"-disp";Stdio.write_file(filename,content||"",0600);Stdio.write_file(debugfilename,"This is your log window\n",0600);return filename;}open();' + + execute "tabnew |r! /usr/local/lib/steam/tools/steam-shell.pike"." '".code."'" + silent !clear + %y+ + let result = @+ + let @a='' + g/Result:/y A + let result = @a + let x = split(result,"\"") + q! + execute("tabnew ".x[1]."-disp"."|sp ".x[1]) +endfunction + +function! Upload() + echo "uploading" +endfunction + + From 1e83f56709bb1da16b27a53bbd3b94ef20252f41 Mon Sep 17 00:00:00 2001 From: Siddhant Date: Thu, 16 Jun 2016 14:20:53 +0530 Subject: [PATCH 26/91] Fixed the logs. --- tools/applauncher.pike | 71 ++++++++++++++++++++++++++++++++++++++++++ tools/steam-shell.vim | 20 ++++++++++-- 2 files changed, 89 insertions(+), 2 deletions(-) diff --git a/tools/applauncher.pike b/tools/applauncher.pike index ae50dba..22b4e11 100644 --- a/tools/applauncher.pike +++ b/tools/applauncher.pike @@ -244,3 +244,74 @@ int applaunch(array(object) objarr,function exit_callback) return -1; } + + +int vim_upload(array(string) filearr, array(object) objarr, array(object) xslobjarr, function|void exit_callback) +{ + int size = sizeof(filearr); + string newcontentx; + array(object) new_statarr = allocate(size); + array(string) new_errorarr = allocate(size); + debugfilearr=allocate(size); + for(int j=0;jget_content(); + + if (!new_statarr[j]) + send_message(sprintf("%s is gone!", filearr[j]),debugfilearr[j]); + + if (new_statarr[j]) + { + newcontentx = Stdio.read_file(filearr[j]); + if (!stringp(newcontentx)) + send_message(sprintf("failed to read %s", filearr[j]),debugfilearr[j]); + } + + + if (stringp(newcontentx) && oldcontentx!="sTeam connection lost.") + { + mixed result=objarr[j]->set_content(newcontentx); + string message=sprintf("File saved - upload: %O\n", result); + send_message(message,debugfilearr[j]); + count=0; //so that compile status can be rewritten for newfile + if (xslobjarr[j]) + { + result=xslobjarr[j]->load_xml_structure(); + message=sprintf("%O: load xml struct: %O", xslobjarr[j], result); + send_message(message,debugfilearr[j]); + } + } + + if(oldcontentx=="sTeam connection lost.") + { + if(k==1){ + send_message("Disconnected\n",debugfilearr[j]); + k--; + } + if(newfileobjarr[j]) + { + send_message("Connected back\n",debugfilearr[j]); + objarr[j] = newfileobjarr[j]; + } + } + + + if(objarr[j]->get_class()=="DocLpc") //if pike script . + { + array errors = objarr[j]->get_errors(); + new_errorarr[j] = sprintf("%O", errors); + send_message("-----------------------------------------\n",debugfilearr[j]); + if(errors==({})) + send_message("Compiled successfully\n",debugfilearr[j]); + else + { + foreach(errors, string err) + send_message(err,debugfilearr[j]); + send_message("Compilation failed\n",debugfilearr[j]); + } + send_message("-----------------------------------------\n",debugfilearr[j]); + } + } +} \ No newline at end of file diff --git a/tools/steam-shell.vim b/tools/steam-shell.vim index 9a19414..22a2710 100644 --- a/tools/steam-shell.vim +++ b/tools/steam-shell.vim @@ -2,6 +2,7 @@ command! -nargs=1 Open call Open() command! Upload call Upload() autocmd BufWritePost * Upload + "Note: This file needs to be included in the applauncher.pike in the function call edit(array(object)) "Function Usage "Enter the Vi insert mode (i) and type the commands @@ -22,22 +23,37 @@ function! Steamshell() endfunction function! Open(name) - let code = 'string open(){string fullpath="'.a:name.'";string pathfact=_Server->get_factory(OBJ(fullpath))->query_attribute("OBJ_NAME");if (pathfact \!= "Document.factory") {write("you can not edit this file.");return 0;}Object obj = OBJ(fullpath);string content = obj->get_content();string dir;dir="/tmp/"+(MIME.encode_base64(Crypto.Random.random_string(10), 1)-("/"))+System.getpid();mkdir(dir,0700);string filename=obj->get_object_id()+"-"+obj->get_identifier();filename=dir+"/"+filename;string debugfilename=filename+"-disp";Stdio.write_file(filename,content||"",0600);Stdio.write_file(debugfilename,"This is your log window\n",0600);return filename;}open();' + "pike code to fetch and store the contents of the file in a temporary file + + let code = 'inherit "/usr/local/lib/steam/tools/applauncher.pike";string open(){string fullpath="'.a:name.'";string pathfact=_Server->get_factory(OBJ(fullpath))->query_attribute("OBJ_NAME");if (pathfact \!= "Document.factory") {write("you can not edit this file.");return 0;}Object obj = OBJ(fullpath);Object xslobj;if(obj->get_identifier()[sizeof(obj->get_identifier())-8..]==".xsl.xml"){string xslnamex=obj->get_identifier()[..sizeof(obj->get_identifier())-9]+ ".xsl";xslobj=obj->get_environment()->get_object_byname(xslnamex);}string content = obj->get_content();string dir;dir="/tmp/"+(MIME.encode_base64(Crypto.Random.random_string(10), 1)-("/"))+System.getpid();mkdir(dir,0700);string filename=obj->get_object_id()+"-"+obj->get_identifier();filename=dir+"/"+filename;string debugfilename=filename+"-disp";Stdio.write_file(filename,content||"",0600);Stdio.write_file(debugfilename,"This is your log window\n",0600);send_message(sprintf("(opened \%O \%s)\n", obj,filename),debugfilename);vim_upload(({filename}),({obj}),({xslobj}));return filename;}open();' + + "store the result of execution of pike script execute "tabnew |r! /usr/local/lib/steam/tools/steam-shell.pike"." '".code."'" silent !clear + "extract the file name from the result %y+ let result = @+ + "echo result let @a='' g/Result:/y A let result = @a let x = split(result,"\"") + "echo x q! execute("tabnew ".x[1]."-disp"."|sp ".x[1]) + + let g:path=a:name endfunction function! Upload() - echo "uploading" + "upload needs to be implemented + write + if exists("g:path") + let code = 'inherit "/usr/local/lib/steam/tools/applauncher.pike";string filename="'.@%.'";Object obj=OBJ("'.g:path.'");Object xslobj;if(obj->get_identifier()[sizeof(obj->get_identifier())-8..]==".xsl.xml"){string xslnamex=obj->get_identifier()[..sizeof(obj->get_identifier())-9]+ ".xsl";xslobj=obj->get_environment()->get_object_byname(xslnamex);}vim_upload(({filename}),({obj}),({xslobj}));' + execute "! /usr/local/lib/steam/tools/steam-shell.pike"." '".code."'" + silent !clear + endif endfunction From f2ae6d5ec26badaf0de80f6a65c8dcd0ec3d2a37 Mon Sep 17 00:00:00 2001 From: Siddhant Date: Thu, 16 Jun 2016 17:08:37 +0530 Subject: [PATCH 27/91] Added comments --- tools/steam-shell.vim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/steam-shell.vim b/tools/steam-shell.vim index 22a2710..cc13fc2 100644 --- a/tools/steam-shell.vim +++ b/tools/steam-shell.vim @@ -32,14 +32,16 @@ function! Open(name) execute "tabnew |r! /usr/local/lib/steam/tools/steam-shell.pike"." '".code."'" silent !clear "extract the file name from the result + "copy the results of pike script to the variable result %y+ let result = @+ - "echo result + "search for Result: and copy that line to register A let @a='' g/Result:/y A let result = @a + "split the line based on space, the name of the file is the second element let x = split(result,"\"") - "echo x + "close the file containing the result of the pike script q! execute("tabnew ".x[1]."-disp"."|sp ".x[1]) From 7c838af396e8b231d3d5e9b10e304ad7bf87d4e0 Mon Sep 17 00:00:00 2001 From: Siddhant Date: Sun, 8 May 2016 16:15:31 +0530 Subject: [PATCH 28/91] Fixed create command for Containers --- tools/steam-shell.pike | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index 7470e7a..db79d87 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -702,8 +702,9 @@ int create_ob(string type,string name) data = ([ "link_to":link_to ]); } object myobj = create_object(type,name,desc,data); - if(type=="Room") + if(type=="Room" || type=="Container") myobj->move(OBJ(getpath())); + return 0; } From 84f0e2b3ce570d3eac34b7c83e3cbf5c9ec87266 Mon Sep 17 00:00:00 2001 From: Siddhant Date: Tue, 10 May 2016 18:32:45 +0530 Subject: [PATCH 29/91] made the improvement as discussed by not checking for the last / using getpath()[-1]==47 --- tools/steam-shell.pike | 37 +++++++------------------------------ 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index db79d87..f215870 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -548,16 +548,8 @@ int goto_room(string where) pathobj = OBJ(where); if(!pathobj) //Relative room checking { - if(getpath()[-1]==47) //check last "/" - { - pathobj = OBJ(getpath()+where); - where=getpath()+where; - } - else - { - pathobj = OBJ(getpath()+"/"+where); - where=getpath()+"/"+where; - } + pathobj = OBJ(getpath()+"/"+where); + where=getpath()+"/"+where; } roomname = pathobj->query_attribute("OBJ_NAME"); string factory = _Server->get_factory(pathobj)->query_attribute("OBJ_NAME"); @@ -628,10 +620,7 @@ int look(string|void str) int take(string name) { string fullpath=""; - if(getpath()[-1]==47) //check last "/" - fullpath = getpath()+name; - else - fullpath = getpath()+"/"+name; + fullpath = getpath()+"/"+name; object orig_file = OBJ(fullpath); if(orig_file) { @@ -647,10 +636,7 @@ int take(string name) int gothrough(string gatename) { string fullpath = ""; - if(getpath()[-1]==47) //check last "/" - fullpath = getpath()+gatename; - else - fullpath = getpath()+"/"+gatename; + fullpath = getpath()+"/"+gatename; object gate = OBJ(fullpath); if(gate) { @@ -676,10 +662,7 @@ int gothrough(string gatename) int delete(string file_cont_name) { string fullpath=""; - if(getpath()[-1]==47) //check last "/" - fullpath = getpath()+file_cont_name; - else - fullpath = getpath()+"/"+file_cont_name; + fullpath = getpath()+"/"+file_cont_name; if(OBJ(fullpath)) return 0; return 0; @@ -712,10 +695,7 @@ int create_ob(string type,string name) int peek(string container) { string fullpath = ""; - if(getpath()[-1]==47) //check last "/" - fullpath = getpath()+container; - else - fullpath = getpath()+"/"+container; + fullpath = getpath()+"/"+container; string pathfact = _Server->get_factory(OBJ(fullpath))->query_attribute("OBJ_NAME"); if(pathfact=="Room.factory") { @@ -763,10 +743,7 @@ int inventory() int editfile(string filename) { string fullpath = ""; - if(getpath()[-1]==47) //check last "/" - fullpath = getpath()+filename; - else - fullpath = getpath()+"/"+filename; + fullpath = getpath()+"/"+filename; string pathfact = _Server->get_factory(OBJ(fullpath))->query_attribute("OBJ_NAME"); if(pathfact=="Document.factory") applaunch(OBJ(fullpath),exitnow); From 8672aa26e176f8b0685a244f93df7df9bde54807 Mon Sep 17 00:00:00 2001 From: Siddhant Date: Tue, 10 May 2016 19:08:45 +0530 Subject: [PATCH 30/91] Added the new feature to provide destination with the create command. Working for Rooms and containers --- tools/steam-shell.pike | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index f215870..7fc34cd 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -48,7 +48,7 @@ room Describe the Room you are currently in. look Look around the Room. take Copy a object in your inventory. gothrough Go through a gate. -create Create an object (File/Container/Exit) in current Room. +create Create an object (File/Container/Exit). Provide the full path of the destination or a . if you want it in current folder. peek Peek through a container. inventory(i) List your inventory. edit Edit a file in the current Room. @@ -82,7 +82,7 @@ hilfe Help for Hilfe commands. write("Go through a gate.\n"); return; case "create": - write("Create an object (File/Container/Exit) in current Room.\n"); + write("Create an object (File/Container/Exit). Provide the full path of the destination or a . if you want it in current folder.\n"); return; case "peek": write("Peek through a container.\n"); @@ -240,6 +240,8 @@ int main(int argc, array(string) argv) myarray[command_arr[0]](command_arr[1],command_arr[2]); else if(num==1) myarray[command_arr[0]](); + else if(num==4) + myarray[command_arr[0]](command_arr[1],command_arr[2],command_arr[3]); }; if(result!=0) @@ -668,7 +670,7 @@ int delete(string file_cont_name) return 0; } -int create_ob(string type,string name) +int create_ob(string type,string name,string destination) { string desc = readln->read("How would you describe it?\n"); mapping data = ([]); @@ -685,8 +687,12 @@ int create_ob(string type,string name) data = ([ "link_to":link_to ]); } object myobj = create_object(type,name,desc,data); - if(type=="Room" || type=="Container") - myobj->move(OBJ(getpath())); + if(type=="Room" || type=="Container"){ + if(destination==".") + myobj->move(OBJ(getpath())); + else + myobj->move(OBJ(destination)); + } return 0; From 30bd57a28034e8460aca8c00d83701b4b8aaee28 Mon Sep 17 00:00:00 2001 From: Siddhant Date: Fri, 13 May 2016 21:31:08 +0530 Subject: [PATCH 31/91] Extended the destination feature of the create command to all type of objects --- tools/steam-shell.pike | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index 7fc34cd..b2cf955 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -675,11 +675,13 @@ int create_ob(string type,string name,string destination) string desc = readln->read("How would you describe it?\n"); mapping data = ([]); type = String.capitalize(type); + if(destination == ".") + destination = getpath(); if(type=="Exit") { object exit_to = OBJ(readln->read("Where do you want to exit to?(full path)\n")); - object exit_from = OBJ(getpath()); - data = ([ "exit_from":exit_from, "exit_to":exit_to ]); +// object exit_from = OBJ(getpath()); + data = ([ "exit_from":OBJ(destination), "exit_to":exit_to ]); } else if(type=="Link") { @@ -687,13 +689,15 @@ int create_ob(string type,string name,string destination) data = ([ "link_to":link_to ]); } object myobj = create_object(type,name,desc,data); - if(type=="Room" || type=="Container"){ +/* if(type=="Room" || type=="Container"){ if(destination==".") myobj->move(OBJ(getpath())); else myobj->move(OBJ(destination)); } - + */ + if(!(type == "Exit")) + myobj->move(OBJ(destination)); return 0; } From ccccfc9a34339b86a41ee4135c8bbb2aae938416 Mon Sep 17 00:00:00 2001 From: Siddhant Date: Sun, 8 May 2016 16:15:31 +0530 Subject: [PATCH 32/91] Fixed create command for Containers --- tools/steam-shell.pike | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index 7470e7a..db79d87 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -702,8 +702,9 @@ int create_ob(string type,string name) data = ([ "link_to":link_to ]); } object myobj = create_object(type,name,desc,data); - if(type=="Room") + if(type=="Room" || type=="Container") myobj->move(OBJ(getpath())); + return 0; } From 8e9714fff2f8645c8067a28b158cc52cda3c22ff Mon Sep 17 00:00:00 2001 From: Siddhant Date: Tue, 10 May 2016 18:32:45 +0530 Subject: [PATCH 33/91] made the improvement as discussed by not checking for the last / using getpath()[-1]==47 --- tools/steam-shell.pike | 37 +++++++------------------------------ 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index db79d87..f215870 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -548,16 +548,8 @@ int goto_room(string where) pathobj = OBJ(where); if(!pathobj) //Relative room checking { - if(getpath()[-1]==47) //check last "/" - { - pathobj = OBJ(getpath()+where); - where=getpath()+where; - } - else - { - pathobj = OBJ(getpath()+"/"+where); - where=getpath()+"/"+where; - } + pathobj = OBJ(getpath()+"/"+where); + where=getpath()+"/"+where; } roomname = pathobj->query_attribute("OBJ_NAME"); string factory = _Server->get_factory(pathobj)->query_attribute("OBJ_NAME"); @@ -628,10 +620,7 @@ int look(string|void str) int take(string name) { string fullpath=""; - if(getpath()[-1]==47) //check last "/" - fullpath = getpath()+name; - else - fullpath = getpath()+"/"+name; + fullpath = getpath()+"/"+name; object orig_file = OBJ(fullpath); if(orig_file) { @@ -647,10 +636,7 @@ int take(string name) int gothrough(string gatename) { string fullpath = ""; - if(getpath()[-1]==47) //check last "/" - fullpath = getpath()+gatename; - else - fullpath = getpath()+"/"+gatename; + fullpath = getpath()+"/"+gatename; object gate = OBJ(fullpath); if(gate) { @@ -676,10 +662,7 @@ int gothrough(string gatename) int delete(string file_cont_name) { string fullpath=""; - if(getpath()[-1]==47) //check last "/" - fullpath = getpath()+file_cont_name; - else - fullpath = getpath()+"/"+file_cont_name; + fullpath = getpath()+"/"+file_cont_name; if(OBJ(fullpath)) return 0; return 0; @@ -712,10 +695,7 @@ int create_ob(string type,string name) int peek(string container) { string fullpath = ""; - if(getpath()[-1]==47) //check last "/" - fullpath = getpath()+container; - else - fullpath = getpath()+"/"+container; + fullpath = getpath()+"/"+container; string pathfact = _Server->get_factory(OBJ(fullpath))->query_attribute("OBJ_NAME"); if(pathfact=="Room.factory") { @@ -763,10 +743,7 @@ int inventory() int editfile(string filename) { string fullpath = ""; - if(getpath()[-1]==47) //check last "/" - fullpath = getpath()+filename; - else - fullpath = getpath()+"/"+filename; + fullpath = getpath()+"/"+filename; string pathfact = _Server->get_factory(OBJ(fullpath))->query_attribute("OBJ_NAME"); if(pathfact=="Document.factory") applaunch(OBJ(fullpath),exitnow); From cdf5d18afaaac0c5fd0264ab6a3c061628e92cf2 Mon Sep 17 00:00:00 2001 From: Siddhant Date: Tue, 10 May 2016 19:08:45 +0530 Subject: [PATCH 34/91] Added the new feature to provide destination with the create command. Working for Rooms and containers --- tools/steam-shell.pike | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index f215870..7fc34cd 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -48,7 +48,7 @@ room Describe the Room you are currently in. look Look around the Room. take Copy a object in your inventory. gothrough Go through a gate. -create Create an object (File/Container/Exit) in current Room. +create Create an object (File/Container/Exit). Provide the full path of the destination or a . if you want it in current folder. peek Peek through a container. inventory(i) List your inventory. edit Edit a file in the current Room. @@ -82,7 +82,7 @@ hilfe Help for Hilfe commands. write("Go through a gate.\n"); return; case "create": - write("Create an object (File/Container/Exit) in current Room.\n"); + write("Create an object (File/Container/Exit). Provide the full path of the destination or a . if you want it in current folder.\n"); return; case "peek": write("Peek through a container.\n"); @@ -240,6 +240,8 @@ int main(int argc, array(string) argv) myarray[command_arr[0]](command_arr[1],command_arr[2]); else if(num==1) myarray[command_arr[0]](); + else if(num==4) + myarray[command_arr[0]](command_arr[1],command_arr[2],command_arr[3]); }; if(result!=0) @@ -668,7 +670,7 @@ int delete(string file_cont_name) return 0; } -int create_ob(string type,string name) +int create_ob(string type,string name,string destination) { string desc = readln->read("How would you describe it?\n"); mapping data = ([]); @@ -685,8 +687,12 @@ int create_ob(string type,string name) data = ([ "link_to":link_to ]); } object myobj = create_object(type,name,desc,data); - if(type=="Room" || type=="Container") - myobj->move(OBJ(getpath())); + if(type=="Room" || type=="Container"){ + if(destination==".") + myobj->move(OBJ(getpath())); + else + myobj->move(OBJ(destination)); + } return 0; From 61dbefcee9d1470852a1a74e70d325f724fa93e7 Mon Sep 17 00:00:00 2001 From: Siddhant Date: Fri, 13 May 2016 21:31:08 +0530 Subject: [PATCH 35/91] Extended the destination feature of the create command to all type of objects --- tools/steam-shell.pike | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index 7fc34cd..b2cf955 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -675,11 +675,13 @@ int create_ob(string type,string name,string destination) string desc = readln->read("How would you describe it?\n"); mapping data = ([]); type = String.capitalize(type); + if(destination == ".") + destination = getpath(); if(type=="Exit") { object exit_to = OBJ(readln->read("Where do you want to exit to?(full path)\n")); - object exit_from = OBJ(getpath()); - data = ([ "exit_from":exit_from, "exit_to":exit_to ]); +// object exit_from = OBJ(getpath()); + data = ([ "exit_from":OBJ(destination), "exit_to":exit_to ]); } else if(type=="Link") { @@ -687,13 +689,15 @@ int create_ob(string type,string name,string destination) data = ([ "link_to":link_to ]); } object myobj = create_object(type,name,desc,data); - if(type=="Room" || type=="Container"){ +/* if(type=="Room" || type=="Container"){ if(destination==".") myobj->move(OBJ(getpath())); else myobj->move(OBJ(destination)); } - + */ + if(!(type == "Exit")) + myobj->move(OBJ(destination)); return 0; } From 2bce94b94f377f32f4a97af1efcd5b6b06f2804c Mon Sep 17 00:00:00 2001 From: Siddhant Date: Sun, 29 May 2016 10:07:49 +0530 Subject: [PATCH 36/91] Added the feature to open multiple files using the edit command in steam-shell --- tools/applauncher.pike | 253 +++++++++++++++++++++++++---------------- tools/steam-shell.pike | 36 ++++-- 2 files changed, 179 insertions(+), 110 deletions(-) diff --git a/tools/applauncher.pike b/tools/applauncher.pike index 8a82d7e..fe894cd 100644 --- a/tools/applauncher.pike +++ b/tools/applauncher.pike @@ -21,171 +21,224 @@ constant cvs_version="$Id: applauncher.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $"; //before using this file, patch the paths for watchforchanges.vim and golden_ratio.vim -object newfileobj; -string content; +array(object) newfileobjarr; +array(string) contentarr; int i=1; -int j=1; +int k=1; int count=0; int set=0; string dir; -string debugfile; +array(string) debugfilearr; +array(string) olderrorsarr; -void upload(object editor, string file, int last_mtime, object obj, object xslobj, function|void exit_callback, string|void olderrors) +void upload(object editor, array(string) filearr ,array(int) last_mtimearr, array(object) objarr, array(object) xslobjarr, function|void exit_callback) { int exit_status = editor->status(); - object new_stat = file_stat(file); - int new_mtime; - string newcontent; - string oldcontent = obj->get_content(); //currently changing - - if((content!=oldcontent)&&(oldcontent!=("sTeam connection lost."||""))&&obj&&(i==1)) - { + int size = sizeof(filearr); + array(object) new_statarr = allocate(size); + array(int) new_mtimearr = allocate(size); + array(string) new_errorarr = allocate(size); + for(int j=0;jget_content(); + if((contentarr[j]!=oldcontentx)&&(oldcontentx!=("sTeam connection lost."||""))&&objarr[j]&&(i==1)) + { i=0; - send_message("File changed on server.\n"); -//Not needed - Stdio.write_file(file, oldcontent||"", 0600); - last_mtime = new_stat->mtime; - } - if (!new_stat) - send_message(sprintf("%s is gone!", file)); + send_message("File changed on server.\n",debugfilearr[j]); + last_mtimearr[j] = new_statarr[j]->mtime; + } - if (new_stat && new_stat->mtime > last_mtime) - { - new_mtime = new_stat->mtime; - newcontent = Stdio.read_file(file); - if (!stringp(newcontent)) - send_message(sprintf("failed to read %s", file)); - } + if (!new_statarr[j]) + send_message(sprintf("%s is gone!", filearr[j]),debugfilearr[j]); - if (stringp(newcontent) && newcontent != content && oldcontent!="sTeam connection lost.") - { - last_mtime=new_mtime; - content = newcontent; //update initial content to new after saving - mixed result=obj->set_content(newcontent); + if (new_statarr[j] && new_statarr[j]->mtime > last_mtimearr[j]) + { + new_mtimearr[j] = new_statarr[j]->mtime; + newcontentx = Stdio.read_file(filearr[j]); + if (!stringp(newcontentx)) + send_message(sprintf("failed to read %s", filearr[j]),debugfilearr[j]); + } + + + if (stringp(newcontentx) && newcontentx != contentarr[j] && oldcontentx!="sTeam connection lost.") + { + last_mtimearr[j]=new_mtimearr[j]; + contentarr[j] = newcontentx; //update initial content to new after saving + mixed result=objarr[j]->set_content(newcontentx); string message=sprintf("File saved - upload: %O\n", result); - olderrors = UNDEFINED; - send_message(message); + olderrorsarr[j] = UNDEFINED; + send_message(message,debugfilearr[j]); count=0; //so that compile status can be rewritten for newfile - if (xslobj) + if (xslobjarr[j]) { - result=xslobj->load_xml_structure(); - message=sprintf("%O: load xml struct: %O", xslobj, result); - send_message(message); + result=xslobjarr[j]->load_xml_structure(); + message=sprintf("%O: load xml struct: %O", xslobjarr[j], result); + send_message(message,debugfilearr[j]); } - } - if(oldcontent=="sTeam connection lost.") - { - if(j==1){ - send_message("Disconnected\n"); - j--; } - if(newfileobj) + + if(oldcontentx=="sTeam connection lost.") + { + if(k==1){ + send_message("Disconnected\n",debugfilearr[j]); + k--; + } + if(newfileobjarr[j]) { - send_message("Connected back\n"); - obj = newfileobj; + send_message("Connected back\n",debugfilearr[j]); + objarr[j] = newfileobjarr[j]; } - } + } - if (exit_status != 2) - { - if(obj->get_class()=="DocLpc") //if pike script . + if (exit_status != 2) { - array errors = obj->get_errors(); - string newerrors = sprintf("%O", errors); - if (newerrors != olderrors) + if(objarr[j]->get_class()=="DocLpc") //if pike script . + { + array errors = objarr[j]->get_errors(); + // string newerrors = sprintf("%O", errors); + new_errorarr[j] = sprintf("%O", errors); + if (new_errorarr[j] != olderrorsarr[j]) { - olderrors = newerrors; - send_message("-----------------------------------------\n"); + olderrorsarr[j] = new_errorarr[j]; + send_message("-----------------------------------------\n",debugfilearr[j]); if(errors==({})) - send_message("Compiled successfully\n"); + send_message("Compiled successfully\n",debugfilearr[j]); else { foreach(errors, string err) - send_message(err); - send_message("Compilation failed\n"); + send_message(err,debugfilearr[j]); + send_message("Compilation failed\n",debugfilearr[j]); } - send_message("-----------------------------------------\n"); + send_message("-----------------------------------------\n",debugfilearr[j]); } } - call_out(upload, 1, editor, file, new_mtime, obj, xslobj, exit_callback, olderrors); - } + } else if (exit_callback) { exit_callback(editor->wait()); // exit(1); } + + } + if(exit_status !=2) + call_out(upload, 1, editor, filearr, new_mtimearr, objarr, xslobjarr, exit_callback); } -void update(object obj) +void update(array(object) obj) { - newfileobj = obj; + for(int j = 0; j < sizeof(obj); j++) + newfileobjarr[j] = obj[j]; } -array edit(object obj) +array edit(array(object) objarr) { #if constant(Crypto.Random) dir="/tmp/"+(MIME.encode_base64(Crypto.Random.random_string(10), 1)-("/"))+System.getpid(); #else dir="/tmp/"+(MIME.encode_base64(Crypto.randomness.pike_random()->read(10), 1)-("/"))+System.getpid(); #endif - string filename=obj->get_object_id()+"-"+obj->get_identifier(); + int size = sizeof(objarr); //get the number of files + contentarr=allocate(size); //made content global, this is content when vim starts and remains same. oldcontent keeps changing in upload function. + debugfilearr=allocate(size); + array(string) filenamearr = allocate(size); + - debugfile = filename+"-disp"; mkdir(dir, 0700); - content=obj->get_content(); //made content global, this is content when vim starts and remains same. oldcontent keeps changing in upload function. - //werror("%O\n", content); - Stdio.write_file(dir+"/"+filename, content||"", 0600); - - Stdio.write_file(dir+"/"+debugfile, "This is your log window\n", 0600); + + //get the filename and debugfile name for all the files + //also get content for all the files + //initialize the files + + for(int j = 0; j < size; j++){ + filenamearr[j] = objarr[j]->get_object_id()+"-"+objarr[j]->get_identifier(); + debugfilearr[j] = filenamearr[j]+"-disp"; + contentarr[j] = objarr[j]->get_content(); + filenamearr[j]=dir+"/"+filenamearr[j]; + Stdio.write_file(filenamearr[j], contentarr[j]||"", 0600); + debugfilearr[j]=dir+"/"+debugfilearr[j]; + Stdio.write_file(debugfilearr[j], "This is your log window\n", 0600); + } + + string comm;//command in string form array command; + //array command=({ "screen", "-X", "screen", "vi", dir+"/"+filename }); //array command=({ "vim", "--servername", "VIM", "--remote-wait", dir+"/"+filename }); - string enveditor = getenv("EDITOR"); - string name = dir+"/"+debugfile; - if((enveditor=="VIM")||(enveditor=="vim")) //full path to .vim files to be mentioned - command=({ "vim","-S", "/usr/local/lib/steam/tools/watchforchanges.vim", "-S", "/usr/local/lib/steam/tools/golden_ratio.vim", dir+"/"+filename, "-c","set splitbelow", "-c" ,sprintf("split|view %s",name), "-c", "wincmd w"}); + + string enveditor = getenv("EDITOR"); + + + if((enveditor=="VIM")||(enveditor=="vim")){ //full path to .vim files to be mentioned + comm="vim*-S*/usr/local/lib/steam/tools/watchforchanges.vim*-S*/usr/local/lib/steam/tools/golden_ratio.vim*-c*edit "+debugfilearr[0]+"|sp "+filenamearr[0]; + if(size>1) + comm = add_file_name(comm,filenamearr[1..],debugfilearr[1..]); + } else if(enveditor=="emacs") - command=({ "emacs", "--eval","(add-hook 'emacs-startup-hook 'toggle-window-spt)", "--eval", "(global-auto-revert-mode t)", dir+"/"+filename, dir+"/"+debugfile, "--eval", "(setq buffer-read-only t)", "--eval", sprintf("(setq frame-title-format \"%s\")",obj->get_identifier()) , "--eval", "(windmove-up)", "--eval", "(enlarge-window 5)"}); - else - command=({ "vi","-S", "/usr/local/lib/steam/tools/watchforchanges.vim", "-S", "/usr/local/lib/steam/tools/golden_ratio.vim", dir+"/"+filename, "-c","set splitbelow", "-c" ,sprintf("split|view %s",name), "-c", "wincmd w"}); + comm="emacs*--eval*(add-hook 'emacs-startup-hook 'toggle-window-spt)*--eval*(global-auto-revert-mode t)"; + for(int j = 0;jget_identifier()) +"*--eval*(windmove-up)*--eval*(enlarge-window 5)"; + else{ + comm="vi*-S*/usr/local/lib/steam/tools/watchforchanges.vim*-S*/usr/local/lib/steam/tools/golden_ratio.vim*-c*edit "+debugfilearr[0]+"|sp "+filenamearr[0]; + + if(size>1) + comm = add_file_name(comm,filenamearr[1..],debugfilearr[1..]); + } + + command=comm/"*"; // convert the string to array. object editor=Process.create_process(command, ([ "cwd":getenv("HOME"), "env":getenv(), "stdin":Stdio.stdin, "stdout":Stdio.stdout, "stderr":Stdio.stderr ])); - return ({ editor, dir+"/"+filename }); + return ({ editor,filenamearr}); } -int send_message(string message) +string add_file_name(string command,array(string) arr,array(string) debug){ + int size = sizeof(arr); + for(int j=0;jget_identifier()[sizeof(obj->get_identifier())-8..]==".xsl.xml") - { - string xslname= - obj->get_identifier()[..sizeof(obj->get_identifier())-9]+ ".xsl"; - xslobj=obj->get_environment()->get_object_byname(xslname); + int size = sizeof(objarr); + array(object) xslobjarr = allocate(size); + for(int j = 0; j < size; j++){ + if(objarr[j]->get_identifier()[sizeof(objarr[j]->get_identifier())-8..]==".xsl.xml") + { + string xslnamex= + objarr[j]->get_identifier()[..sizeof(objarr[j]->get_identifier())-9]+ ".xsl"; + xslobjarr[j]=objarr[j]->get_environment()->get_object_byname(xslnamex); + } } object editor; - string file; - [editor, file]=edit(obj); - mixed status; + array(string) filearr; + [editor,filearr]=edit(objarr); + + // mixed status; //while(!(status=editor->status())) + + array(int) filestatarr = allocate(size); + for(int j = 0; j < size; j++){ + send_message(sprintf("(opened %O %s)\n", objarr[j], filearr[j]),debugfilearr[j]); + filestatarr[j] = file_stat(filearr[j])->mtime; + } - send_message(sprintf("(opened %O %s)\n", obj, file)); - call_out(upload, 1, editor, file, file_stat(file)->mtime, obj, xslobj, exit_callback); + olderrorsarr = allocate(size); + call_out(upload, 1, editor, filearr, filestatarr, objarr, xslobjarr, exit_callback); + editor.wait(); // signal(signum("SIGINT"), prompt); + return -1; } diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index b2cf955..0400799 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -219,8 +219,7 @@ int main(int argc, array(string) argv) ]); // Regexp.SimpleRegexp a = Regexp.SimpleRegexp("[a-zA-Z]* [\"|'][a-zA-Z _-]*[\"|']"); array(string) command_arr; - while((command=readln->read( - sprintf("%s", (handler->state->finishedp()?getstring(1):getstring(2)))))) + while((command=readln->read(sprintf("%s", (handler->state->finishedp()?getstring(1):getstring(2)))))) { if(sizeof(command)) { @@ -242,10 +241,13 @@ int main(int argc, array(string) argv) myarray[command_arr[0]](); else if(num==4) myarray[command_arr[0]](command_arr[1],command_arr[2],command_arr[3]); + else + myarray[command_arr[0]](@command_arr[1..]); }; if(result!=0) { + write(result[0]); write("Wrong command.||maybe some bug.\n"); } } @@ -750,15 +752,29 @@ int inventory() display("other files", others); } -int editfile(string filename) +int editfile(string...args) { - string fullpath = ""; - fullpath = getpath()+"/"+filename; - string pathfact = _Server->get_factory(OBJ(fullpath))->query_attribute("OBJ_NAME"); - if(pathfact=="Document.factory") - applaunch(OBJ(fullpath),exitnow); - else - write("You can't edit a "+pathfact[0..sizeof(pathfact)-8]); + int size = sizeof(args); + if(size<1){ + write("Please provide a file name\n"); + return 0; + } + array(string) fullpatharr = allocate(size); + array(string) pathfactarr = allocate(size); + array(object) obj = allocate(size); + for(int j = 0;jget_factory(OBJ(fullpatharr[j]))->query_attribute("OBJ_NAME"); + + if(pathfactarr[j]!="Document.factory"){ + write("You can't edit a "+pathfactarr[j][0..sizeof(pathfactarr[j])-8]); + return 0; + } + obj[j] = OBJ(fullpatharr[j]); + } + + applaunch(obj,exitnow); + return 0; } From b7fea355041795b2d4ce42f55817e188c998d9cc Mon Sep 17 00:00:00 2001 From: Siddhant Gupta Date: Mon, 30 May 2016 08:09:11 +0530 Subject: [PATCH 37/91] Missed braces. Fixed it --- tools/applauncher.pike | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/applauncher.pike b/tools/applauncher.pike index fe894cd..6cbf984 100644 --- a/tools/applauncher.pike +++ b/tools/applauncher.pike @@ -175,12 +175,13 @@ array edit(array(object) objarr) if(size>1) comm = add_file_name(comm,filenamearr[1..],debugfilearr[1..]); } - else if(enveditor=="emacs") + else if(enveditor=="emacs"){ comm="emacs*--eval*(add-hook 'emacs-startup-hook 'toggle-window-spt)*--eval*(global-auto-revert-mode t)"; for(int j = 0;jget_identifier()) +"*--eval*(windmove-up)*--eval*(enlarge-window 5)"; + } else{ comm="vi*-S*/usr/local/lib/steam/tools/watchforchanges.vim*-S*/usr/local/lib/steam/tools/golden_ratio.vim*-c*edit "+debugfilearr[0]+"|sp "+filenamearr[0]; From 9217c0af116edeeb38630584aa7c58dfb6059b3b Mon Sep 17 00:00:00 2001 From: Siddhant Date: Mon, 30 May 2016 11:05:48 +0530 Subject: [PATCH 38/91] Made edit.pike compatible with the new applaunch.pike. Note this is just a temporary solution --- tools/edit.pike | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/edit.pike b/tools/edit.pike index 3e7512f..bf3bbe3 100755 --- a/tools/edit.pike +++ b/tools/edit.pike @@ -41,7 +41,8 @@ void ping(string host, string port, string user, string|void pw) user_obj = _Server->get_module("users")->lookup(options->user); gp = user_obj->get_groups(); get_file_object(); - update(file); + array(object) filearr = ({file}); + update(filearr); } } } @@ -80,7 +81,8 @@ int main(int argc, array(string) argv) // write(mystr); // array(string) gps = ({ "Admin" , "coder" , "help" , "PrivGroups" , "WikiGroups" , "sTeam" }); get_file_object(); - return applaunch(file,demo); + array(object) filearr = ({file}); + return applaunch(filearr,demo); } void demo(){} From d057c1b0e34314efd94c9f1e3514e73992b2f47d Mon Sep 17 00:00:00 2001 From: Siddhant Date: Mon, 30 May 2016 14:37:45 +0530 Subject: [PATCH 39/91] Fixed applauncher to work with edit.pike --- tools/applauncher.pike | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/applauncher.pike b/tools/applauncher.pike index 6cbf984..43a6664 100644 --- a/tools/applauncher.pike +++ b/tools/applauncher.pike @@ -128,6 +128,7 @@ void upload(object editor, array(string) filearr ,array(int) last_mtimearr, arra void update(array(object) obj) { + newfileobjarr = allocate(sizeof(obj)); for(int j = 0; j < sizeof(obj); j++) newfileobjarr[j] = obj[j]; } From 1aa48843f60d4c58351b8b7dda0b21b6ea1e00a7 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Sun, 19 Jun 2016 17:04:27 +0530 Subject: [PATCH 40/91] use a named vim register instead of + --- tools/steam-shell.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/steam-shell.vim b/tools/steam-shell.vim index cc13fc2..a4c024c 100644 --- a/tools/steam-shell.vim +++ b/tools/steam-shell.vim @@ -33,8 +33,9 @@ function! Open(name) silent !clear "extract the file name from the result "copy the results of pike script to the variable result - %y+ - let result = @+ + let @a='' + %ya + let result = @a "search for Result: and copy that line to register A let @a='' g/Result:/y A From a36ee197b053b521a9ee552fb3658e03c42b8075 Mon Sep 17 00:00:00 2001 From: Siddhant Gupta Date: Tue, 21 Jun 2016 16:02:42 +0530 Subject: [PATCH 41/91] Changed Object to object. Using of Object was giving Warning: Using object as program identifier. --- tools/steam-shell.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/steam-shell.vim b/tools/steam-shell.vim index a4c024c..e188035 100644 --- a/tools/steam-shell.vim +++ b/tools/steam-shell.vim @@ -26,7 +26,7 @@ function! Open(name) "pike code to fetch and store the contents of the file in a temporary file - let code = 'inherit "/usr/local/lib/steam/tools/applauncher.pike";string open(){string fullpath="'.a:name.'";string pathfact=_Server->get_factory(OBJ(fullpath))->query_attribute("OBJ_NAME");if (pathfact \!= "Document.factory") {write("you can not edit this file.");return 0;}Object obj = OBJ(fullpath);Object xslobj;if(obj->get_identifier()[sizeof(obj->get_identifier())-8..]==".xsl.xml"){string xslnamex=obj->get_identifier()[..sizeof(obj->get_identifier())-9]+ ".xsl";xslobj=obj->get_environment()->get_object_byname(xslnamex);}string content = obj->get_content();string dir;dir="/tmp/"+(MIME.encode_base64(Crypto.Random.random_string(10), 1)-("/"))+System.getpid();mkdir(dir,0700);string filename=obj->get_object_id()+"-"+obj->get_identifier();filename=dir+"/"+filename;string debugfilename=filename+"-disp";Stdio.write_file(filename,content||"",0600);Stdio.write_file(debugfilename,"This is your log window\n",0600);send_message(sprintf("(opened \%O \%s)\n", obj,filename),debugfilename);vim_upload(({filename}),({obj}),({xslobj}));return filename;}open();' + let code = 'inherit "/usr/local/lib/steam/tools/applauncher.pike";string open(){string fullpath="'.a:name.'";string pathfact=_Server->get_factory(OBJ(fullpath))->query_attribute("OBJ_NAME");if (pathfact \!= "Document.factory") {write("you can not edit this file.");return 0;}object obj = OBJ(fullpath);object xslobj;if(obj->get_identifier()[sizeof(obj->get_identifier())-8..]==".xsl.xml"){string xslnamex=obj->get_identifier()[..sizeof(obj->get_identifier())-9]+ ".xsl";xslobj=obj->get_environment()->get_object_byname(xslOnamex);}string content = obj->get_content();string dir;dir="/tmp/"+(MIME.encode_base64(Crypto.Random.random_string(10), 1)-("/"))+System.getpid();mkdir(dir,0700);string filename=obj->get_object_id()+"-"+obj->get_identifier();filename=dir+"/"+filename;string debugfilename=filename+"-disp";Stdio.write_file(filename,content||"",0600);Stdio.write_file(debugfilename,"This is your log window\n",0600);send_message(sprintf("(opened \%O \%s)\n", obj,filename),debugfilename);vim_upload(({filename}),({obj}),({xslobj}));return filename;}open();' "store the result of execution of pike script execute "tabnew |r! /usr/local/lib/steam/tools/steam-shell.pike"." '".code."'" @@ -53,7 +53,7 @@ function! Upload() "upload needs to be implemented write if exists("g:path") - let code = 'inherit "/usr/local/lib/steam/tools/applauncher.pike";string filename="'.@%.'";Object obj=OBJ("'.g:path.'");Object xslobj;if(obj->get_identifier()[sizeof(obj->get_identifier())-8..]==".xsl.xml"){string xslnamex=obj->get_identifier()[..sizeof(obj->get_identifier())-9]+ ".xsl";xslobj=obj->get_environment()->get_object_byname(xslnamex);}vim_upload(({filename}),({obj}),({xslobj}));' + let code = 'inherit "/usr/local/lib/steam/tools/applauncher.pike";string filename="'.@%.'";object obj=OBJ("'.g:path.'");object xslobj;if(obj->get_identifier()[sizeof(obj->get_identifier())-8..]==".xsl.xml"){string xslnamex=obj->get_identifier()[..sizeof(obj->get_identifier())-9]+ ".xsl";xslobj=obj->get_environment()->get_object_byname(xslnamex);}vim_upload(({filename}),({obj}),({xslobj}));' execute "! /usr/local/lib/steam/tools/steam-shell.pike"." '".code."'" silent !clear endif From 7ed2115c1c92f792c97245fd3233842a854ba34c Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Tue, 21 Jun 2016 23:38:02 +0530 Subject: [PATCH 42/91] functionality to create and join groups --- tools/steam-shell.pike | 74 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index b2cf955..c89e963 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -52,6 +52,7 @@ create Create an object (File/Container/Exit). Provide the full path of peek Peek through a container. inventory(i) List your inventory. edit Edit a file in the current Room. +group Use group commands. (list/join/leave) hilfe Help for Hilfe commands. "; switch(line) { @@ -94,6 +95,9 @@ hilfe Help for Hilfe commands. case "edit": write("Edit a file in the current Room.\n"); return; + case "group": + write("Use group commands. (list/join/leave)"); + return; //Hilfe internal help case "me more": write( documentation_help_me_more ); @@ -216,6 +220,7 @@ int main(int argc, array(string) argv) "inventory" : inventory, "i" : inventory, "edit" : editfile, + "group" : group, ]); // Regexp.SimpleRegexp a = Regexp.SimpleRegexp("[a-zA-Z]* [\"|'][a-zA-Z _-]*[\"|']"); array(string) command_arr; @@ -358,6 +363,7 @@ mapping assign(object conn, object _Server, object users) "look" : look, "take" : take, "gothrough" : gothrough, + "group" : group, // from database.h : "_SECURITY" : _Server->get_module("security"), @@ -389,6 +395,62 @@ mapping assign(object conn, object _Server, object users) ]); } +void group(string command,void|string name) +{ + switch(command) + { + case "list": + mapping mp = Process.run("tput cols"); + int screenwidth = (int)mp["stdout"]; + string toappend=""; + write("My groups\n"); + array(object) joined_groups = me->get_groups(); + foreach(joined_groups,object group) + { + toappend = toappend + group->get_name() +"\n"; + } + write("%-$*s\n", screenwidth,toappend); + write("\nOther groups\n"); + toappend=""; + array(object) other_groups = _Server->get_module("groups")->get_groups(); + foreach(other_groups,object group) + { + if(search(joined_groups,group)==-1) + toappend = toappend + group->get_name() + "\n"; + } + write("%-$*s\n", screenwidth,toappend); + write("\n"); + return; + case "join": + if(!stringp(name)){ + write("group join "); + return; + } + object group = _Server->get_module("groups")->get_group(name); + if(group == 0){ + write("The group does not exists\n"); + return; + } + int result = group->add_member(me); + switch(result){ + case 1:write("Joined group "+name+"\n"); + break; + case 0:write("Couldn't join group "+name+"\n"); + break; + case -1:write("pending\n"); + break; + case -2:write("pending failed"); + break; + } + return; + case "leave": + return; + default: + write("Group command: list/join/leave\n"); + } +} + + // create new sTeam objects // with code taken from the web script create.pike mixed create_object(string|void objectclass, string|void name, void|string desc, void|mapping data) @@ -688,6 +750,11 @@ int create_ob(string type,string name,string destination) object link_to = OBJ(readln->read("Where does the link lead?\n")); data = ([ "link_to":link_to ]); } + else if(type=="Group") + { + string parent = readln->read("Subgroup of?\n"); + data = (["parentgroup":parent]); + } object myobj = create_object(type,name,desc,data); /* if(type=="Room" || type=="Container"){ if(destination==".") @@ -696,9 +763,12 @@ int create_ob(string type,string name,string destination) myobj->move(OBJ(destination)); } */ - if(!(type == "Exit")) + if(!(type == "Exit" || type=="Group")) myobj->move(OBJ(destination)); - + if(type=="Group") + { + myobj->add_member(me); + } return 0; } From 232c945ffaa8ca2ab9c795663fbdb16a7e133b9f Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Thu, 23 Jun 2016 09:16:32 +0530 Subject: [PATCH 43/91] code to leave groups. --- tools/steam-shell.pike | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index c89e963..8e83dfd 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -444,6 +444,16 @@ void group(string command,void|string name) } return; case "leave": + if(!stringp(name)){ + write("group leave "); + return; + } + group = _Server->get_module("groups")->get_group(name); + if(group == 0){ + write("The group does not exists\n"); + return; + } + group->remove_member(me); return; default: write("Group command: list/join/leave\n"); From f520a7d8e475094f2d85fa938a84ac79a9c140f6 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Thu, 23 Jun 2016 16:39:14 +0530 Subject: [PATCH 44/91] changed the interface for join and leave --- tools/steam-shell.pike | 61 ++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index 8e83dfd..570a8d6 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -52,6 +52,8 @@ create Create an object (File/Container/Exit). Provide the full path of peek Peek through a container. inventory(i) List your inventory. edit Edit a file in the current Room. +join Join a group. +leave Leave a group. group Use group commands. (list/join/leave) hilfe Help for Hilfe commands. "; @@ -95,8 +97,14 @@ hilfe Help for Hilfe commands. case "edit": write("Edit a file in the current Room.\n"); return; + case "join": + write("Join a group.\n"); + return; + case "leave": + write("Leave a group.\n"); + return; case "group": - write("Use group commands. (list/join/leave)"); + write("Use group commands. (list/join/leave)\n"); return; //Hilfe internal help case "me more": @@ -220,6 +228,8 @@ int main(int argc, array(string) argv) "inventory" : inventory, "i" : inventory, "edit" : editfile, + "join" : join, + "leave" : leave, "group" : group, ]); // Regexp.SimpleRegexp a = Regexp.SimpleRegexp("[a-zA-Z]* [\"|'][a-zA-Z _-]*[\"|']"); @@ -363,6 +373,8 @@ mapping assign(object conn, object _Server, object users) "look" : look, "take" : take, "gothrough" : gothrough, + "join" : join, + "leave" : leave, "group" : group, // from database.h : @@ -421,9 +433,34 @@ void group(string command,void|string name) write("%-$*s\n", screenwidth,toappend); write("\n"); return; - case "join": - if(!stringp(name)){ - write("group join "); + default: + write("Group command: list/join/leave\n"); + } +} + +void leave(string what,void|string name) +{ + if(what=="group") + { + if(!stringp(name)){ + write("leave group \n"); + return; + } + object group = _Server->get_module("groups")->get_group(name); + if(group == 0){ + write("The group does not exists\n"); + return; + } + group->remove_member(me); + } +} + +void join(string what,void|string name) +{ + if(what=="group") + { + if(!stringp(name)){ + write("join group \n"); return; } object group = _Server->get_module("groups")->get_group(name); @@ -442,25 +479,9 @@ void group(string command,void|string name) case -2:write("pending failed"); break; } - return; - case "leave": - if(!stringp(name)){ - write("group leave "); - return; - } - group = _Server->get_module("groups")->get_group(name); - if(group == 0){ - write("The group does not exists\n"); - return; - } - group->remove_member(me); - return; - default: - write("Group command: list/join/leave\n"); } } - // create new sTeam objects // with code taken from the web script create.pike mixed create_object(string|void objectclass, string|void name, void|string desc, void|mapping data) From 06ecc06898060a4b66c16e1dc609e75c44905791 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Thu, 23 Jun 2016 19:08:19 +0530 Subject: [PATCH 45/91] Changed get_list to allow it to be extended for any kind of object. --- tools/steam-shell.pike | 149 ++++++++++++++++++----------------------- 1 file changed, 65 insertions(+), 84 deletions(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index 570a8d6..9350946 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -24,6 +24,7 @@ constant cvs_version="$Id: debug.pike.in,v 1.1 2008/03/31 13:39:57 exodusd Exp $ inherit "applauncher.pike"; #define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) +#include Stdio.Readline readln; mapping options; @@ -54,7 +55,6 @@ inventory(i) List your inventory. edit Edit a file in the current Room. join Join a group. leave Leave a group. -group Use group commands. (list/join/leave) hilfe Help for Hilfe commands. "; switch(line) { @@ -103,9 +103,6 @@ hilfe Help for Hilfe commands. case "leave": write("Leave a group.\n"); return; - case "group": - write("Use group commands. (list/join/leave)\n"); - return; //Hilfe internal help case "me more": write( documentation_help_me_more ); @@ -230,7 +227,6 @@ int main(int argc, array(string) argv) "edit" : editfile, "join" : join, "leave" : leave, - "group" : group, ]); // Regexp.SimpleRegexp a = Regexp.SimpleRegexp("[a-zA-Z]* [\"|'][a-zA-Z _-]*[\"|']"); array(string) command_arr; @@ -375,7 +371,6 @@ mapping assign(object conn, object _Server, object users) "gothrough" : gothrough, "join" : join, "leave" : leave, - "group" : group, // from database.h : "_SECURITY" : _Server->get_module("security"), @@ -407,37 +402,6 @@ mapping assign(object conn, object _Server, object users) ]); } -void group(string command,void|string name) -{ - switch(command) - { - case "list": - mapping mp = Process.run("tput cols"); - int screenwidth = (int)mp["stdout"]; - string toappend=""; - write("My groups\n"); - array(object) joined_groups = me->get_groups(); - foreach(joined_groups,object group) - { - toappend = toappend + group->get_name() +"\n"; - } - write("%-$*s\n", screenwidth,toappend); - write("\nOther groups\n"); - toappend=""; - array(object) other_groups = _Server->get_module("groups")->get_groups(); - foreach(other_groups,object group) - { - if(search(joined_groups,group)==-1) - toappend = toappend + group->get_name() + "\n"; - } - write("%-$*s\n", screenwidth,toappend); - write("\n"); - return; - default: - write("Group command: list/join/leave\n"); - } -} - void leave(string what,void|string name) { if(what=="group") @@ -560,72 +524,89 @@ int list(string what) if(sizeof(display)==0) toappend = "There are no "+what+" in this room\n"; else - toappend = "Here is a list of all "+what+" in the current room\n"; + toappend = "Here is a list of all "+what+"\n"; foreach(display,string str) { - a=a+(str+" "); + a=a+(str+"\n"); if(str=="Invalid command") { flag=1; write(str+"\n"); } } - if(flag==0) - write(toappend+a+"\n\n"); + if(flag==0){ + mapping mp = Process.run("tput cols"); + int screenwidth = (int)mp["stdout"]; + write(toappend + "\n"); + write("%-$*s\n", screenwidth,a); + write("\n"); + } return 0; } array(string) get_list(string what,string|object|void lpath) { -// string name; -// object to; - array(string) gates=({}),containers=({}),documents=({}),rooms = ({}),rest=({}); -// mapping(string:object) s = ([ ]); + array(string) whatlist = ({}); object pathobj; - if(!lpath) - pathobj = OBJ(getpath()); - else if(stringp(lpath)) - pathobj = OBJ(lpath); - else if(objectp(lpath)) - pathobj = lpath; -// string pathfact = _Server->get_factory(pathobj)->query_attribute("OBJ_NAME"); - mixed all = pathobj->get_inventory_by_class(0x3cffffff); //CLASS_ALL - foreach(all, object obj) + if(!lpath) + pathobj = OBJ(getpath()); + else if(stringp(lpath)) + pathobj = OBJ(lpath); + else if(objectp(lpath)) + pathobj = lpath; + switch (what) { - string fact_name = _Server->get_factory(obj)->query_attribute("OBJ_NAME"); - string obj_name = obj->query_attribute("OBJ_NAME"); -// write("normally : "+obj_name+"\n"); - if(fact_name=="Document.factory") - documents = Array.push(documents,obj_name); -// write(obj_name+"\n"); - else if(fact_name=="Exit.factory"){ - string fullgate = obj_name+" : "+obj->get_exit()->query_attribute("OBJ_NAME"); - gates = Array.push(gates,fullgate); -// write("in gates : "+fullgate+"\n"); + case "containers": + { + mixed all = pathobj->get_inventory_by_class(CLASS_CONTAINER); + foreach(all, object obj) + { + string fact_name = _Server->get_factory(obj)->query_attribute("OBJ_NAME"); + string obj_name = obj->query_attribute("OBJ_NAME"); + whatlist = Array.push(whatlist,obj_name); + } } - else if(fact_name=="Container.factory") - containers = Array.push(containers,obj_name); -// write("in containers : "+obj_name+"\n"); - else if(fact_name=="Room.factory") - rooms = Array.push(rooms,obj_name); - else - rest = Array.push(rest, obj_name); + break; + case "files": + { + mixed all = pathobj->get_inventory_by_class(CLASS_DOCUMENT|CLASS_DOCLPC|CLASS_DOCEXTERN|CLASS_DOCHTML|CLASS_DOCXML|CLASS_DOCXSL); + foreach(all, object obj) + { + string fact_name = _Server->get_factory(obj)->query_attribute("OBJ_NAME"); + string obj_name = obj->query_attribute("OBJ_NAME"); + whatlist = Array.push(whatlist,obj_name); + } + } + break; + case "exits": + case "gates": + case "rooms": + { + mixed all = pathobj->get_inventory_by_class(CLASS_ROOM|CLASS_EXIT); + foreach(all, object obj) + { + string fact_name = _Server->get_factory(obj)->query_attribute("OBJ_NAME"); + string obj_name = obj->query_attribute("OBJ_NAME"); + whatlist = Array.push(whatlist,obj_name); + } + } + break; + case "groups": + { + array(object) groups = _Server->get_module("groups")->get_groups(); + foreach(groups,object group) + { + string obj_name = group->get_name(); + whatlist = Array.push(whatlist,obj_name); + } + } + break; + default: + whatlist = ({"Invalid command"}); } - if(what=="gates") - return gates; - else if(what=="rooms") - return rooms; - else if(what=="containers") - return containers; - else if(what=="files") - return documents; - else if(what=="others") - return rest; - else - return ({"Invalid command"}); + return whatlist; } - int goto_room(string where) { string roomname=""; From e455442d7327aa632122308b291d760cec9bd84e Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Sun, 26 Jun 2016 21:25:02 +0530 Subject: [PATCH 46/91] Fixed a typing mistake --- tools/steam-shell.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/steam-shell.vim b/tools/steam-shell.vim index e188035..19d8fd2 100644 --- a/tools/steam-shell.vim +++ b/tools/steam-shell.vim @@ -26,7 +26,7 @@ function! Open(name) "pike code to fetch and store the contents of the file in a temporary file - let code = 'inherit "/usr/local/lib/steam/tools/applauncher.pike";string open(){string fullpath="'.a:name.'";string pathfact=_Server->get_factory(OBJ(fullpath))->query_attribute("OBJ_NAME");if (pathfact \!= "Document.factory") {write("you can not edit this file.");return 0;}object obj = OBJ(fullpath);object xslobj;if(obj->get_identifier()[sizeof(obj->get_identifier())-8..]==".xsl.xml"){string xslnamex=obj->get_identifier()[..sizeof(obj->get_identifier())-9]+ ".xsl";xslobj=obj->get_environment()->get_object_byname(xslOnamex);}string content = obj->get_content();string dir;dir="/tmp/"+(MIME.encode_base64(Crypto.Random.random_string(10), 1)-("/"))+System.getpid();mkdir(dir,0700);string filename=obj->get_object_id()+"-"+obj->get_identifier();filename=dir+"/"+filename;string debugfilename=filename+"-disp";Stdio.write_file(filename,content||"",0600);Stdio.write_file(debugfilename,"This is your log window\n",0600);send_message(sprintf("(opened \%O \%s)\n", obj,filename),debugfilename);vim_upload(({filename}),({obj}),({xslobj}));return filename;}open();' + let code = 'inherit "/usr/local/lib/steam/tools/applauncher.pike";string open(){string fullpath="'.a:name.'";string pathfact=_Server->get_factory(OBJ(fullpath))->query_attribute("OBJ_NAME");if (pathfact \!= "Document.factory") {write("you can not edit this file.");return 0;}object obj = OBJ(fullpath);object xslobj;if(obj->get_identifier()[sizeof(obj->get_identifier())-8..]==".xsl.xml"){string xslnamex=obj->get_identifier()[..sizeof(obj->get_identifier())-9]+ ".xsl";xslobj=obj->get_environment()->get_object_byname(xslnamex);}string content = obj->get_content();string dir;dir="/tmp/"+(MIME.encode_base64(Crypto.Random.random_string(10), 1)-("/"))+System.getpid();mkdir(dir,0700);string filename=obj->get_object_id()+"-"+obj->get_identifier();filename=dir+"/"+filename;string debugfilename=filename+"-disp";Stdio.write_file(filename,content||"",0600);Stdio.write_file(debugfilename,"This is your log window\n",0600);send_message(sprintf("(opened \%O \%s)\n", obj,filename),debugfilename);vim_upload(({filename}),({obj}),({xslobj}));return filename;}open();' "store the result of execution of pike script execute "tabnew |r! /usr/local/lib/steam/tools/steam-shell.pike"." '".code."'" From c85c181f36864daeb951aaff129cafc1445fcaae Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Mon, 27 Jun 2016 17:45:47 +0530 Subject: [PATCH 47/91] moved initialization of global variables to init from main in debug.pike --- tools/debug.pike | 203 ++++++++++++++++++++++++----------------------- 1 file changed, 102 insertions(+), 101 deletions(-) diff --git a/tools/debug.pike b/tools/debug.pike index ef31eef..60929dc 100755 --- a/tools/debug.pike +++ b/tools/debug.pike @@ -88,10 +88,109 @@ object handler, conn; int main(int argc, array(string) argv) { - options=init(argv); + init(argv); + handler->add_input_line("start backend"); + string command; + handler->p->set_server_filepath(_Server->get_module("filepath:tree")); //sending the filepath module to tab completion for query/set attribute. + while((command=readln->read( + sprintf("%s", (handler->state->finishedp()?getstring(1):getstring(2)))))) + { + if(sizeof(command)) + { + Stdio.write_file(options->historyfile, readln->get_history()->encode()); + handler->add_input_line(command); + handler->p->set(handler->variables); +// array hist = handler->history->status()/"\n"; +// if(hist) +// if(search(hist[sizeof(hist)-3],"sTeam connection lost.")!=-1){ +// handler->write("came in here\n"); +// flag=0; +// } + continue; + } +// else { continue; } + } + handler->add_input_line("exit"); +} + +void init(array argv) +{ + options = ([ "file":"/etc/shadow" ]); + + array opt=Getopt.find_all_options(argv,aggregate( + ({"file",Getopt.HAS_ARG,({"-f","--file"})}), + ({"host",Getopt.HAS_ARG,({"-h","--host"})}), + ({"user",Getopt.HAS_ARG,({"-u","--user"})}), + ({"port",Getopt.HAS_ARG,({"-p","--port"})}), + )); + + options->historyfile=getenv("HOME")+"/.steam_history"; + + foreach(opt, array option) + { + options[option[0]]=option[1]; + } + if(!options->host) + options->host="127.0.0.1"; + if(!options->user) + options->user="root"; + if(!options->port) + options->port=1900; + else + options->port=(int)options->port; + + string server_path = "/usr/local/lib/steam"; + //change this to working directory + + master()->add_include_path(server_path+"/server/include"); + master()->add_program_path(server_path+"/server/"); + master()->add_program_path(server_path+"/conf/"); + master()->add_program_path(server_path+"/spm/"); + master()->add_program_path(server_path+"/server/net/coal/"); + + conn = ((program)"client_base.pike")(); + + int start_time = time(); + + //connect to the server + werror("Connecting to sTeam server...\n"); + while ( !conn->connect_server(options->host, options->port) ) + { + if ( time() - start_time > 120 ) + { + throw (({" Couldn't connect to server. Please check steam.log for details! \n", backtrace()})); + } + werror("Failed to connect... still trying ... (server running ?)\n"); + sleep(10); + } + + ping(); + + //No password is required for user guest + if(lower_case(options->user) != "guest") + { + mixed err; + int tries=3; + //readln->set_echo( 0 ); + do + { + pw = Input.read_password( sprintf("Password for %s@%s", options->user, + options->host), "steam" ); + } + while((err = catch(conn->login(options->user, pw, 1))) && --tries); + //readln->set_echo( 1 ); + + if ( err != 0 ) + { + werror("Failed to log in!\nWrong Password!\n"); + exit(1); + } + } + + //initialize global variables _Server=conn->SteamObj(0); users=_Server->get_module("users"); - all = assign(conn,_Server,users); + all=assign(conn,_Server,users); all = all + (([ "PSTAT_FAIL_DELETED" : -3, "PSTAT_FAIL_UNSERIALIZE" : -2, @@ -481,7 +580,7 @@ int main(int argc, array(string) argv) ])); - handler = Handler(all); + handler=Handler(all); array history=(Stdio.read_file(options->historyfile)||"")/"\n"; if(history[-1]!="") history+=({""}); @@ -489,104 +588,6 @@ int main(int argc, array(string) argv) readline_history=Stdio.Readline.History(512, history); readln->enable_history(readline_history); - - handler->add_input_line("start backend"); - - string command; - handler->p->set_server_filepath(_Server->get_module("filepath:tree")); //sending the filepath module to tab completion for query/set attribute. - while((command=readln->read( - sprintf("%s", (handler->state->finishedp()?getstring(1):getstring(2)))))) - { - if(sizeof(command)) - { - Stdio.write_file(options->historyfile, readln->get_history()->encode()); - handler->add_input_line(command); - handler->p->set(handler->variables); -// array hist = handler->history->status()/"\n"; -// if(hist) -// if(search(hist[sizeof(hist)-3],"sTeam connection lost.")!=-1){ -// handler->write("came in here\n"); -// flag=0; -// } - continue; - } -// else { continue; } - } - handler->add_input_line("exit"); -} - -mapping init(array argv) -{ - mapping options = ([ "file":"/etc/shadow" ]); - - array opt=Getopt.find_all_options(argv,aggregate( - ({"file",Getopt.HAS_ARG,({"-f","--file"})}), - ({"host",Getopt.HAS_ARG,({"-h","--host"})}), - ({"user",Getopt.HAS_ARG,({"-u","--user"})}), - ({"port",Getopt.HAS_ARG,({"-p","--port"})}), - )); - - options->historyfile=getenv("HOME")+"/.steam_history"; - - foreach(opt, array option) - { - options[option[0]]=option[1]; - } - if(!options->host) - options->host="127.0.0.1"; - if(!options->user) - options->user="root"; - if(!options->port) - options->port=1900; - else - options->port=(int)options->port; - - string server_path = "/usr/local/lib/steam"; - //change this to working directory - - master()->add_include_path(server_path+"/server/include"); - master()->add_program_path(server_path+"/server/"); - master()->add_program_path(server_path+"/conf/"); - master()->add_program_path(server_path+"/spm/"); - master()->add_program_path(server_path+"/server/net/coal/"); - - conn = ((program)"client_base.pike")(); - - int start_time = time(); - - werror("Connecting to sTeam server...\n"); - while ( !conn->connect_server(options->host, options->port) ) - { - if ( time() - start_time > 120 ) - { - throw (({" Couldn't connect to server. Please check steam.log for details! \n", backtrace()})); - } - werror("Failed to connect... still trying ... (server running ?)\n"); - sleep(10); - } - - ping(); - if(lower_case(options->user) == "guest") - return options; - - mixed err; - int tries=3; - //readln->set_echo( 0 ); - do - { - pw = Input.read_password( sprintf("Password for %s@%s", options->user, - options->host), "steam" ); - //pw=readln->read(sprintf("passwd for %s@%s: ", options->user, options->host)); - } - while((err = catch(conn->login(options->user, pw, 1))) && --tries); - //readln->set_echo( 1 ); - - if ( err != 0 ) - { - werror("Failed to log in!\nWrong Password!\n"); - exit(1); - } - return options; } mapping assign(object conn, object _Server, object users) From b9c4f4c92fa23e1314d0cf6f3ebe250b13f07206 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Mon, 27 Jun 2016 17:47:27 +0530 Subject: [PATCH 48/91] added the login command to relogin --- tools/debug.pike | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/debug.pike b/tools/debug.pike index 60929dc..550722a 100755 --- a/tools/debug.pike +++ b/tools/debug.pike @@ -603,6 +603,7 @@ mapping assign(object conn, object _Server, object users) "me" : users->lookup(options->user), "edit" : applaunch, "create" : create_object, + "login" : login, // from database.h : "_SECURITY" : _Server->get_module("security"), @@ -634,6 +635,15 @@ mapping assign(object conn, object _Server, object users) ]); } +int login(string user) +{ + //conn->logout(); + init(({"","-u",user})); + handler->p->set_server_filepath(_Server->get_module("filepath:tree")); + return 1; +} + + // create new sTeam objects // with code taken from the web script create.pike mixed create_object(string|void objectclass, string|void name, void|string desc, void|mapping data) From 65d4721f73649e9d7556e4ed52bc776d4458b2fd Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Tue, 28 Jun 2016 20:55:34 +0530 Subject: [PATCH 49/91] removed the common code from steam-shell.pike --- tools/steam-shell.pike | 78 +++--------------------------------------- 1 file changed, 4 insertions(+), 74 deletions(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index 7470e7a..ada1b42 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -23,6 +23,7 @@ constant cvs_version="$Id: debug.pike.in,v 1.1 2008/03/31 13:39:57 exodusd Exp $"; inherit "applauncher.pike"; +inherit "client.pike"; #define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) Stdio.Readline readln; @@ -184,7 +185,9 @@ object handler, conn; mapping myarray; int main(int argc, array(string) argv) { - options=init(argv); + options = ([ "file":"/etc/shadow" ]); + options = options + init(argv); + options->historyfile=getenv("HOME")+"/.steam_history"; _Server=conn->SteamObj(0); users=_Server->get_module("users"); me = users->lookup(options->user); @@ -263,79 +266,6 @@ int main(int argc, array(string) argv) handler->add_input_line("exit"); } -mapping init(array argv) -{ - mapping options = ([ "file":"/etc/shadow" ]); - - array opt=Getopt.find_all_options(argv,aggregate( - ({"file",Getopt.HAS_ARG,({"-f","--file"})}), - ({"host",Getopt.HAS_ARG,({"-h","--host"})}), - ({"user",Getopt.HAS_ARG,({"-u","--user"})}), - ({"port",Getopt.HAS_ARG,({"-p","--port"})}), - )); - - options->historyfile=getenv("HOME")+"/.steam_history"; - - foreach(opt, array option) - { - options[option[0]]=option[1]; - } - if(!options->host) - options->host="127.0.0.1"; - if(!options->user) - options->user="root"; - if(!options->port) - options->port=1900; - else - options->port=(int)options->port; - - string server_path = "/usr/local/lib/steam"; - - master()->add_include_path(server_path+"/server/include"); - master()->add_program_path(server_path+"/server/"); - master()->add_program_path(server_path+"/conf/"); - master()->add_program_path(server_path+"/spm/"); - master()->add_program_path(server_path+"/server/net/coal/"); - - conn = ((program)"client_base.pike")(); - - int start_time = time(); - - werror("Connecting to sTeam server...\n"); - while ( !conn->connect_server(options->host, options->port) ) - { - if ( time() - start_time > 120 ) - { - throw (({" Couldn't connect to server. Please check steam.log for details! \n", backtrace()})); - } - werror("Failed to connect... still trying ... (server running ?)\n"); - sleep(10); - } - - ping(); - if(lower_case(options->user) == "guest") - return options; - - mixed err; - int tries=3; - //readln->set_echo( 0 ); - do - { - pw = Input.read_password( sprintf("Password for %s@%s", options->user, - options->host), "steam" ); - //pw=readln->read(sprintf("passwd for %s@%s: ", options->user, options->host)); - } - while((err = catch(conn->login(options->user, pw, 1))) && --tries); - //readln->set_echo( 1 ); - - if ( err != 0 ) - { - werror("Failed to log in!\nWrong Password!\n"); - exit(1); - } - return options; -} - mapping assign(object conn, object _Server, object users) { return ([ From e28e2f3ea19ee378cec67262d53f8b02c3e79cbe Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Tue, 28 Jun 2016 21:14:57 +0530 Subject: [PATCH 50/91] removed the common code for debug.pike --- tools/debug.pike | 79 +++--------------------------------------------- 1 file changed, 4 insertions(+), 75 deletions(-) diff --git a/tools/debug.pike b/tools/debug.pike index ef31eef..e1821c3 100755 --- a/tools/debug.pike +++ b/tools/debug.pike @@ -23,6 +23,7 @@ constant cvs_version="$Id: debug.pike.in,v 1.1 2008/03/31 13:39:57 exodusd Exp $"; inherit "applauncher.pike"; +inherit "client.pike"; Stdio.Readline readln; mapping options; @@ -88,7 +89,9 @@ object handler, conn; int main(int argc, array(string) argv) { - options=init(argv); + options = ([ "file":"/etc/shadow" ]); + options= options + init(argv); + options->historyfile=getenv("HOME")+"/.steam_history"; _Server=conn->SteamObj(0); users=_Server->get_module("users"); all = assign(conn,_Server,users); @@ -515,80 +518,6 @@ int main(int argc, array(string) argv) handler->add_input_line("exit"); } -mapping init(array argv) -{ - mapping options = ([ "file":"/etc/shadow" ]); - - array opt=Getopt.find_all_options(argv,aggregate( - ({"file",Getopt.HAS_ARG,({"-f","--file"})}), - ({"host",Getopt.HAS_ARG,({"-h","--host"})}), - ({"user",Getopt.HAS_ARG,({"-u","--user"})}), - ({"port",Getopt.HAS_ARG,({"-p","--port"})}), - )); - - options->historyfile=getenv("HOME")+"/.steam_history"; - - foreach(opt, array option) - { - options[option[0]]=option[1]; - } - if(!options->host) - options->host="127.0.0.1"; - if(!options->user) - options->user="root"; - if(!options->port) - options->port=1900; - else - options->port=(int)options->port; - - string server_path = "/usr/local/lib/steam"; - //change this to working directory - - master()->add_include_path(server_path+"/server/include"); - master()->add_program_path(server_path+"/server/"); - master()->add_program_path(server_path+"/conf/"); - master()->add_program_path(server_path+"/spm/"); - master()->add_program_path(server_path+"/server/net/coal/"); - - conn = ((program)"client_base.pike")(); - - int start_time = time(); - - werror("Connecting to sTeam server...\n"); - while ( !conn->connect_server(options->host, options->port) ) - { - if ( time() - start_time > 120 ) - { - throw (({" Couldn't connect to server. Please check steam.log for details! \n", backtrace()})); - } - werror("Failed to connect... still trying ... (server running ?)\n"); - sleep(10); - } - - ping(); - if(lower_case(options->user) == "guest") - return options; - - mixed err; - int tries=3; - //readln->set_echo( 0 ); - do - { - pw = Input.read_password( sprintf("Password for %s@%s", options->user, - options->host), "steam" ); - //pw=readln->read(sprintf("passwd for %s@%s: ", options->user, options->host)); - } - while((err = catch(conn->login(options->user, pw, 1))) && --tries); - //readln->set_echo( 1 ); - - if ( err != 0 ) - { - werror("Failed to log in!\nWrong Password!\n"); - exit(1); - } - return options; -} - mapping assign(object conn, object _Server, object users) { return ([ From 5f3bc0711aeb41bebe618aa48f3735f3db852233 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Tue, 28 Jun 2016 21:16:27 +0530 Subject: [PATCH 51/91] Added the check for -f option in client.pike --- tools/client.pike | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/client.pike b/tools/client.pike index d8a2528..eacc7b8 100755 --- a/tools/client.pike +++ b/tools/client.pike @@ -39,6 +39,7 @@ mapping init(array argv) mapping options = ([ ]); array opt=Getopt.find_all_options(argv,aggregate( + ({"file",Getopt.HAS_ARG,({"-f","--file"})}), ({"host",Getopt.HAS_ARG,({"-h","--host"})}), ({"user",Getopt.HAS_ARG,({"-u","--user"})}), ({"port",Getopt.HAS_ARG,({"-p","--port"})}), From 66b1a59d9fa793e7a2a0240ffe6e3b3a6ee3167e Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Tue, 28 Jun 2016 21:57:22 +0530 Subject: [PATCH 52/91] removed the common code from edit.pike --- tools/edit.pike | 90 ++++--------------------------------------------- 1 file changed, 7 insertions(+), 83 deletions(-) diff --git a/tools/edit.pike b/tools/edit.pike index 3e7512f..128ac49 100755 --- a/tools/edit.pike +++ b/tools/edit.pike @@ -23,6 +23,7 @@ constant cvs_version="$Id: edit.pike.in,v 1.0 2010/09/15 14:19:52 martin Exp $"; inherit "applauncher.pike"; +inherit "client.pike"; //inherit "/usr/local/lib/steam/server/modules/groups.pike"; void ping(string host, string port, string user, string|void pw) { @@ -51,13 +52,15 @@ object conn; mapping conn_options = ([]); object _Server,user_obj,file; array(object) gp; +mapping options = ([ ]); int main(int argc, array(string) argv) { - - + // program pGroup = (program)"/classes/Group.pike"; - mapping options=init(argv); + options=init(argv); + options->file = argv[-1]; + ping(options->host, options->port, options->user, pw); // gp=_Server->get_module("groups")->lookup("helloworld"); _Server=conn->SteamObj(0); user_obj = _Server->get_module("users")->lookup(options->user); @@ -117,83 +120,4 @@ void get_file_object() } if (file->get_class() == "Link") file = file->get_link_object(); -} - - mapping options = ([ ]); -mapping init(array argv) -{ - - array opt=Getopt.find_all_options(argv,aggregate( - ({"host",Getopt.HAS_ARG,({"-h","--host"})}), - ({"user",Getopt.HAS_ARG,({"-u","--user"})}), - ({"port",Getopt.HAS_ARG,({"-p","--port"})}), - )); - - foreach(opt, array option) - { - options[option[0]]=option[1]; - } - if(!options->host) - options->host="127.0.0.1"; - if(!options->user) - options->user="root"; - if(!options->port) - options->port=1900; - else - options->port=(int)options->port; - - options->file = argv[-1]; - - string server_path = "/usr/local/lib/steam"; - - master()->add_include_path(server_path+"/server/include"); - master()->add_program_path(server_path+"/server/"); - master()->add_program_path(server_path+"/server/modules/groups.pike"); - master()->add_program_path(server_path+"/conf/"); - master()->add_program_path(server_path+"/spm/"); - master()->add_program_path(server_path+"/server/net/coal/"); - - conn = ((program)"client_base.pike")(); -// groups_pgm = ((program)"groups.pike")(); - int start_time = time(); - - werror("Connecting to sTeam server...\n"); - while ( !conn->connect_server(options->host, options->port) ) - { - if ( time() - start_time > 120 ) - { - throw (({" Couldn't connect to server. Please check steam.log for details! \n", backtrace()})); - } - werror("Failed to connect... still trying ... (server running ?)\n"); - sleep(10); - } - - if(lower_case(options->user) == "guest") - { - ping(options->host, options->port, options->user); - return options; - } - - mixed err; - string pw; - int tries=3; - //readln->set_echo( 0 ); - do - { - pw = Input.read_password( sprintf("Password for %s@%s", options->user, - options->host), "steam" ); -// pw ="steam"; - //pw=readln->read(sprintf("passwd for %s@%s: ", options->user, options->host)); - } - while((err = catch(conn->login(options->user, pw, 1))) && --tries); - //readln->set_echo( 1 ); - - if ( err != 0 ) - { - werror("Failed to log in!\nWrong Password!\n"); - exit(1); - } - ping(options->host, options->port, options->user, pw); - return options; -} - +} \ No newline at end of file From 01f372505311adef0145fdf606a295c894719d06 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Tue, 28 Jun 2016 21:58:08 +0530 Subject: [PATCH 53/91] made variable pw global in client.pike --- tools/client.pike | 2 +- tools/debug.pike | 2 +- tools/steam-shell.pike | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/client.pike b/tools/client.pike index eacc7b8..45d98a6 100755 --- a/tools/client.pike +++ b/tools/client.pike @@ -33,6 +33,7 @@ void ping() object conn; mapping options = ([ ]); +string pw; mapping init(array argv) { @@ -86,7 +87,6 @@ mapping init(array argv) return options; mixed err; - string pw; int tries=3; //readln->set_echo( 0 ); do diff --git a/tools/debug.pike b/tools/debug.pike index e1821c3..d9a3a9a 100755 --- a/tools/debug.pike +++ b/tools/debug.pike @@ -28,7 +28,7 @@ inherit "client.pike"; Stdio.Readline readln; mapping options; int flag=1,c=1; -string pw,str; +string str; class Handler { diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index ada1b42..f54650f 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -29,7 +29,7 @@ inherit "client.pike"; Stdio.Readline readln; mapping options; int flag=1,c=1; -string pw,str; +string str; object me; protected class StashHelp { From 6c2251311faff753111d939618ec06aca0c61196 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Wed, 29 Jun 2016 16:10:41 +0530 Subject: [PATCH 54/91] logging out the previous user before login and standardized the init function --- tools/debug.pike | 158 +++++++++++++++++++++++++---------------------- 1 file changed, 84 insertions(+), 74 deletions(-) diff --git a/tools/debug.pike b/tools/debug.pike index 550722a..39793da 100755 --- a/tools/debug.pike +++ b/tools/debug.pike @@ -88,7 +88,7 @@ object handler, conn; int main(int argc, array(string) argv) { - init(argv); + initialize(argv); handler->add_input_line("start backend"); string command; handler->p->set_server_filepath(_Server->get_module("filepath:tree")); //sending the filepath module to tab completion for query/set attribute. @@ -113,80 +113,11 @@ int main(int argc, array(string) argv) handler->add_input_line("exit"); } -void init(array argv) +void initialize(array argv) { options = ([ "file":"/etc/shadow" ]); - - array opt=Getopt.find_all_options(argv,aggregate( - ({"file",Getopt.HAS_ARG,({"-f","--file"})}), - ({"host",Getopt.HAS_ARG,({"-h","--host"})}), - ({"user",Getopt.HAS_ARG,({"-u","--user"})}), - ({"port",Getopt.HAS_ARG,({"-p","--port"})}), - )); - + options = options + init(argv); options->historyfile=getenv("HOME")+"/.steam_history"; - - foreach(opt, array option) - { - options[option[0]]=option[1]; - } - if(!options->host) - options->host="127.0.0.1"; - if(!options->user) - options->user="root"; - if(!options->port) - options->port=1900; - else - options->port=(int)options->port; - - string server_path = "/usr/local/lib/steam"; - //change this to working directory - - master()->add_include_path(server_path+"/server/include"); - master()->add_program_path(server_path+"/server/"); - master()->add_program_path(server_path+"/conf/"); - master()->add_program_path(server_path+"/spm/"); - master()->add_program_path(server_path+"/server/net/coal/"); - - conn = ((program)"client_base.pike")(); - - int start_time = time(); - - //connect to the server - werror("Connecting to sTeam server...\n"); - while ( !conn->connect_server(options->host, options->port) ) - { - if ( time() - start_time > 120 ) - { - throw (({" Couldn't connect to server. Please check steam.log for details! \n", backtrace()})); - } - werror("Failed to connect... still trying ... (server running ?)\n"); - sleep(10); - } - - ping(); - - //No password is required for user guest - if(lower_case(options->user) != "guest") - { - mixed err; - int tries=3; - //readln->set_echo( 0 ); - do - { - pw = Input.read_password( sprintf("Password for %s@%s", options->user, - options->host), "steam" ); - } - while((err = catch(conn->login(options->user, pw, 1))) && --tries); - //readln->set_echo( 1 ); - - if ( err != 0 ) - { - werror("Failed to log in!\nWrong Password!\n"); - exit(1); - } - } - //initialize global variables _Server=conn->SteamObj(0); users=_Server->get_module("users"); @@ -588,6 +519,85 @@ void init(array argv) readline_history=Stdio.Readline.History(512, history); readln->enable_history(readline_history); + +} + +mapping init(array argv) +{ + mapping options = ([ "file":"/etc/shadow" ]); + + array opt=Getopt.find_all_options(argv,aggregate( + ({"file",Getopt.HAS_ARG,({"-f","--file"})}), + ({"host",Getopt.HAS_ARG,({"-h","--host"})}), + ({"user",Getopt.HAS_ARG,({"-u","--user"})}), + ({"port",Getopt.HAS_ARG,({"-p","--port"})}), + )); + + options->historyfile=getenv("HOME")+"/.steam_history"; + + foreach(opt, array option) + { + options[option[0]]=option[1]; + } + if(!options->host) + options->host="127.0.0.1"; + if(!options->user) + options->user="root"; + if(!options->port) + options->port=1900; + else + options->port=(int)options->port; + + string server_path = "/usr/local/lib/steam"; + //change this to working directory + + master()->add_include_path(server_path+"/server/include"); + master()->add_program_path(server_path+"/server/"); + master()->add_program_path(server_path+"/conf/"); + master()->add_program_path(server_path+"/spm/"); + master()->add_program_path(server_path+"/server/net/coal/"); + + conn = ((program)"client_base.pike")(); + + int start_time = time(); + + //connect to the server + werror("Connecting to sTeam server...\n"); + while ( !conn->connect_server(options->host, options->port) ) + { + if ( time() - start_time > 120 ) + { + throw (({" Couldn't connect to server. Please check steam.log for details! \n", backtrace()})); + } + werror("Failed to connect... still trying ... (server running ?)\n"); + sleep(10); + } + + ping(); + + //No password is required for user guest + if(lower_case(options->user) == "guest") + return options; + + mixed err; + int tries=3; + //readln->set_echo( 0 ); + do + { + pw = Input.read_password( sprintf("Password for %s@%s", options->user, + options->host), "steam" ); + } + while((err = catch(conn->login(options->user, pw, 1))) && --tries); + //readln->set_echo( 1 ); + + if ( err != 0 ) + { + werror("Failed to log in!\nWrong Password!\n"); + exit(1); + } + + + return options; } mapping assign(object conn, object _Server, object users) @@ -637,8 +647,8 @@ mapping assign(object conn, object _Server, object users) int login(string user) { - //conn->logout(); - init(({"","-u",user})); + conn->logout(); + initialize(({"","-u",user})); handler->p->set_server_filepath(_Server->get_module("filepath:tree")); return 1; } From 44910ace24be1745f0c03d78ed1881d4510603f5 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Thu, 30 Jun 2016 13:45:39 +0530 Subject: [PATCH 55/91] Showing status message for leave group command. --- tools/steam-shell.pike | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index 9350946..91e4ebd 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -415,7 +415,14 @@ void leave(string what,void|string name) write("The group does not exists\n"); return; } - group->remove_member(me); + if(group->remove_member(me)) + { + write("Left group "+name+"\n"); + } + else + { + write("You are not a member of the group "+name+"\n"); + } } } From 70b2e86649a4daeec1d611bcd53810c9398bcce8 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Thu, 30 Jun 2016 18:52:45 +0530 Subject: [PATCH 56/91] separated out rooms and gates --- tools/steam-shell.pike | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index 9350946..72271ad 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -580,9 +580,19 @@ array(string) get_list(string what,string|object|void lpath) break; case "exits": case "gates": + { + mixed all = pathobj->get_inventory_by_class(CLASS_EXIT); + foreach(all, object obj) + { + string fact_name = _Server->get_factory(obj)->query_attribute("OBJ_NAME"); + string obj_name = obj->query_attribute("OBJ_NAME"); + whatlist = Array.push(whatlist,obj_name); + } + } + break; case "rooms": { - mixed all = pathobj->get_inventory_by_class(CLASS_ROOM|CLASS_EXIT); + mixed all = pathobj->get_inventory_by_class(CLASS_ROOM); foreach(all, object obj) { string fact_name = _Server->get_factory(obj)->query_attribute("OBJ_NAME"); From 2aafc32a41aaf08f42d019829c02942f4127f433 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Fri, 1 Jul 2016 17:20:37 +0530 Subject: [PATCH 57/91] Added the case others and removed some redundant code --- tools/steam-shell.pike | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index 72271ad..c7e5677 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -561,7 +561,6 @@ array(string) get_list(string what,string|object|void lpath) mixed all = pathobj->get_inventory_by_class(CLASS_CONTAINER); foreach(all, object obj) { - string fact_name = _Server->get_factory(obj)->query_attribute("OBJ_NAME"); string obj_name = obj->query_attribute("OBJ_NAME"); whatlist = Array.push(whatlist,obj_name); } @@ -572,7 +571,6 @@ array(string) get_list(string what,string|object|void lpath) mixed all = pathobj->get_inventory_by_class(CLASS_DOCUMENT|CLASS_DOCLPC|CLASS_DOCEXTERN|CLASS_DOCHTML|CLASS_DOCXML|CLASS_DOCXSL); foreach(all, object obj) { - string fact_name = _Server->get_factory(obj)->query_attribute("OBJ_NAME"); string obj_name = obj->query_attribute("OBJ_NAME"); whatlist = Array.push(whatlist,obj_name); } @@ -584,7 +582,6 @@ array(string) get_list(string what,string|object|void lpath) mixed all = pathobj->get_inventory_by_class(CLASS_EXIT); foreach(all, object obj) { - string fact_name = _Server->get_factory(obj)->query_attribute("OBJ_NAME"); string obj_name = obj->query_attribute("OBJ_NAME"); whatlist = Array.push(whatlist,obj_name); } @@ -595,7 +592,6 @@ array(string) get_list(string what,string|object|void lpath) mixed all = pathobj->get_inventory_by_class(CLASS_ROOM); foreach(all, object obj) { - string fact_name = _Server->get_factory(obj)->query_attribute("OBJ_NAME"); string obj_name = obj->query_attribute("OBJ_NAME"); whatlist = Array.push(whatlist,obj_name); } @@ -611,6 +607,20 @@ array(string) get_list(string what,string|object|void lpath) } } break; + case "others": + { + mixed all = pathobj->get_inventory_by_class(CLASS_ALL); + foreach(all, object obj) + { + string fact_name = _Server->get_factory(obj)->query_attribute("OBJ_NAME"); + if(!(fact_name == "Group.factory" || fact_name == "Room.factory" || fact_name == "Exit.factory" || fact_name == "Container.factory" || fact_name == "Document.factory" || fact_name == "DocExtern.factory")) + { + string obj_name = obj->query_attribute("OBJ_NAME"); + whatlist = Array.push(whatlist,obj_name); + } + } + } + break; default: whatlist = ({"Invalid command"}); } From f851c28aa84d887957f3618a492a94a38f5f6d33 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Fri, 1 Jul 2016 18:31:03 +0530 Subject: [PATCH 58/91] Changed gothrough to enter and extended it for rooms. --- tools/steam-shell.pike | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index c7e5677..27368d1 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -48,7 +48,7 @@ title Set your own description. room Describe the Room you are currently in. look Look around the Room. take Copy a object in your inventory. -gothrough Go through a gate. +enter Enter a Room, Gate or Exit. create Create an object (File/Container/Exit). Provide the full path of the destination or a . if you want it in current folder. peek Peek through a container. inventory(i) List your inventory. @@ -81,8 +81,8 @@ hilfe Help for Hilfe commands. case "take": write("Copy a object in your inventory.\n"); return; - case "gothrough": - write("Go through a gate.\n"); + case "enter": + write("Enter a Room, Gate or Exit.\n"); return; case "create": write("Create an object (File/Container/Exit). Provide the full path of the destination or a . if you want it in current folder.\n"); @@ -219,7 +219,7 @@ int main(int argc, array(string) argv) "room" : desc_room, "look" : look, "take" : take, - "gothrough" : gothrough, + "enter" : enter, "create" : create_ob, "peek" : peek, "inventory" : inventory, @@ -368,7 +368,7 @@ mapping assign(object conn, object _Server, object users) "room" : desc_room, "look" : look, "take" : take, - "gothrough" : gothrough, + "enter" : enter, "join" : join, "leave" : leave, @@ -729,15 +729,19 @@ int take(string name) return 0; } -int gothrough(string gatename) +int enter(string gatename) { string fullpath = ""; fullpath = getpath()+"/"+gatename; object gate = OBJ(fullpath); if(gate) { - object exit = gate->get_exit(); - string exit_path1 = "",exit_path2 = ""; + string exit_path1 = fullpath,exit_path2 = ""; + if(_Server->get_factory(gate)->query_attribute("OBJ_NAME")=="Exit.factory") + { + object exit = gate->get_exit(); + exit_path1 = exit->query_attribute("OBJ_PATH"); //change to object_to_path + } // exit_path1 = _Server->get_module("filepath:tree")->check_tilde(exit); // exit_path2 = _Server->get_module("filepath:tree")->object_to_path(exit); // if(exit_path1!="") @@ -746,7 +750,7 @@ int gothrough(string gatename) // goto_room(exit_path2); // else // write("Problem with object_to_path\n"); - exit_path1 = exit->query_attribute("OBJ_PATH"); //change to object_to_path + if(exit_path1!="") goto_room(exit_path1); } From 76d12c9663a3fadc2d6a9adfc5e6f51728b72287 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Mon, 4 Jul 2016 14:01:58 +0530 Subject: [PATCH 59/91] changed the output of look --- tools/steam-shell.pike | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index c7e5677..d762126 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -578,18 +578,9 @@ array(string) get_list(string what,string|object|void lpath) break; case "exits": case "gates": - { - mixed all = pathobj->get_inventory_by_class(CLASS_EXIT); - foreach(all, object obj) - { - string obj_name = obj->query_attribute("OBJ_NAME"); - whatlist = Array.push(whatlist,obj_name); - } - } - break; case "rooms": { - mixed all = pathobj->get_inventory_by_class(CLASS_ROOM); + mixed all = pathobj->get_inventory_by_class(CLASS_ROOM|CLASS_EXIT); foreach(all, object obj) { string obj_name = obj->query_attribute("OBJ_NAME"); @@ -706,8 +697,6 @@ int look(string|void str) write("---------------\n"); list("containers"); write("---------------\n"); - list("gates"); - write("---------------\n"); list("rooms"); write("---------------\n"); return 0; From 8ca0f01295f1871d4f2d748503a72ea5ca7e438e Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Wed, 6 Jul 2016 14:28:53 +0530 Subject: [PATCH 60/91] fixed the return values of functions in steam-shell --- tools/steam-shell.pike | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index 7470e7a..e55da52 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -477,7 +477,7 @@ int list(string what) } if(flag==0) write(toappend+a+"\n\n"); - return 0; + return !flag;//flag = 1 when str = Invalid command that means execution failed } array(string) get_list(string what,string|object|void lpath) @@ -574,24 +574,28 @@ int goto_room(string where) { write("Please specify path to room. Not a "+((factory/".")[0])+"\n"); me->move(OBJ(oldpath)); + return 0; } else if(error) { write("Please specify correct path to a room.\n"); + return 0; } // } // roomname = pathobj->query_attribute("OBJ_NAME"); // write("You are now inside "+roomname+"\n"); - return 0; + return 1; } int set_title(string desc) { if(users->lookup(options->user)->set_attribute("OBJ_DESC",desc)) write("You are now described as - "+desc+"\n"); - else + else{ write("Cannot set description.\n"); - return 0; + return 0; + } + return 1; } int desc_room() @@ -603,7 +607,7 @@ int desc_room() if((desc=="")||(Regexp.match("^ +$",desc))) desc = "This room does not have a description yet.\n"; write("You are currently in "+pathobj->query_attribute("OBJ_NAME")+"\n"+desc+"\n"); - return 0; + return 1; } int look(string|void str) @@ -622,7 +626,7 @@ int look(string|void str) write("---------------\n"); list("rooms"); write("---------------\n"); - return 0; + return 1; } int take(string name) @@ -639,9 +643,11 @@ int take(string name) dup_file->move(me); write(name+" copied to your rucksack.\n"); } - else + else{ write("Please mention a file in this room."); - return 0; + return 0; + } + return 1; } int gothrough(string gatename) @@ -669,8 +675,11 @@ int gothrough(string gatename) goto_room(exit_path1); } else + { write(gatename+" is not reachable from current room\n"); - return 0; + return 0; + } + return 1; } int delete(string file_cont_name) @@ -705,7 +714,7 @@ int create_ob(string type,string name) if(type=="Room") myobj->move(OBJ(getpath())); - return 0; + return 1; } int peek(string container) @@ -731,6 +740,7 @@ int peek(string container) write("You peek into "+container+"\n\n"); display("containers", conts); display("files", files); + return 1; } void display(string type, array(string) strs) @@ -757,6 +767,7 @@ int inventory() display("containers", conts); display("files", files); display("other files", others); + return 1; } int editfile(string filename) @@ -769,9 +780,11 @@ int editfile(string filename) string pathfact = _Server->get_factory(OBJ(fullpath))->query_attribute("OBJ_NAME"); if(pathfact=="Document.factory") applaunch(OBJ(fullpath),exitnow); - else + else{ write("You can't edit a "+pathfact[0..sizeof(pathfact)-8]); - return 0; + return 0; + } + return 1; } void exitnow() From 809eff52ed0ffc7ffdfc5fb74f29061efdbf76a8 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Thu, 7 Jul 2016 11:29:04 +0530 Subject: [PATCH 61/91] first attempt to establish a framework for testing --- tools/tests/test | 45 +++++++++++++++++++++++++++++++++++++++++++ tools/tests/test.in | 38 ++++++++++++++++++++++++++++++++++++ tools/tests/test.pike | 36 ++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 tools/tests/test create mode 100644 tools/tests/test.in create mode 100644 tools/tests/test.pike diff --git a/tools/tests/test b/tools/tests/test new file mode 100644 index 0000000..0a94d9b --- /dev/null +++ b/tools/tests/test @@ -0,0 +1,45 @@ +/home/siddhant/Documents/sTeam/tools/test.in:1: test 1, expected result: RUN +mixed a() { add_constant("host","127.0.0.1"); + add_constant("port",1900); + add_constant("server_path","/usr/local/lib/steam"); +; } +.... +/home/siddhant/Documents/sTeam/tools/test.in:6: test 2, expected result: RUN +mixed a() { + + master()->add_include_path(server_path+"/server/include"); + master()->add_program_path(server_path+"/server/"); + master()->add_program_path(server_path+"/conf/"); + master()->add_program_path(server_path+"/spm/"); + master()->add_program_path(server_path+"/server/net/coal/"); +; } +.... +/home/siddhant/Documents/sTeam/tools/test.in:15: test 3, expected result: RUN +mixed a() { add_constant("conn",((program)"../spm/client_base.pike")());; } +.... +/home/siddhant/Documents/sTeam/tools/test.in:17: test 4, expected result: RUN +mixed a() { + conn->connect_server(host,port); + conn->login("root","steam",1); +; } +.... +/home/siddhant/Documents/sTeam/tools/test.in:22: test 5, expected result: RUN +mixed a() { add_constant("_Server",conn->SteamObj(0)); +; } +.... +/home/siddhant/Documents/sTeam/tools/test.in:25: test 6, expected result: RUN +mixed a() { add_constant("me",_Server->get_module("users")->lookup("root")); +; } +.... +/home/siddhant/Documents/sTeam/tools/test.in:29: test 7, expected result: EQ +mixed a() { + #define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) + me->move(OBJ("/home/root")); + string oldpath = me->get_last_trail()->query_attribute("OBJ_PATH"); + me->move(OBJ("/new1")); + string newpath = me->get_last_trail()->query_attribute("OBJ_PATH"); + if(oldpath=="/home/root" && newpath=="/new1") return 1; + else return 0; +; } +mixed b() { return 1; } +.... diff --git a/tools/tests/test.in b/tools/tests/test.in new file mode 100644 index 0000000..6641155 --- /dev/null +++ b/tools/tests/test.in @@ -0,0 +1,38 @@ +test_do(add_constant("host","127.0.0.1"); + add_constant("port",1900); + add_constant("server_path","/usr/local/lib/steam"); +) + +test_do([[ + + master()->add_include_path(server_path+"/server/include"); + master()->add_program_path(server_path+"/server/"); + master()->add_program_path(server_path+"/conf/"); + master()->add_program_path(server_path+"/spm/"); + master()->add_program_path(server_path+"/server/net/coal/"); +]]) + +test_do(add_constant("conn",((program)"../spm/client_base.pike")());) + +test_do([[ + conn->connect_server(host,port); + conn->login("root","steam",1); +]]) + +test_do( + add_constant("_Server",conn->SteamObj(0)); +) +test_do( + add_constant("me",_Server->get_module("users")->lookup("root")); +) + +test_any([[ + #define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) + me->move(OBJ("/home/root")); + string oldpath = me->get_last_trail()->query_attribute("OBJ_PATH"); + me->move(OBJ("/new1")); + string newpath = me->get_last_trail()->query_attribute("OBJ_PATH"); + if(oldpath=="/home/root" && newpath=="/new1") return 1; + else return 0; +]],1) + diff --git a/tools/tests/test.pike b/tools/tests/test.pike new file mode 100644 index 0000000..afdd245 --- /dev/null +++ b/tools/tests/test.pike @@ -0,0 +1,36 @@ +#define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) + +object _Server; +object me; + +void init(){ + string host = "127.0.0.1"; + int port = 1900; + string server_path = "/usr/local/lib/steam"; + master()->add_include_path(server_path+"/server/include"); + master()->add_program_path(server_path+"/server/"); + master()->add_program_path(server_path+"/conf/"); + master()->add_program_path(server_path+"/spm/"); + master()->add_program_path(server_path+"/server/net/coal/"); + object conn = ((program)"../spm/client_base.pike")(); + conn->connect_server(host,port); + conn->login("root","steam",1); + _Server = conn->SteamObj(0); + me = _Server->get_module("users")->lookup("root"); + +} + +int main(){ + init(); + int pass = 0; + string path = me->get_last_trail()->query_attribute("OBJ_PATH"); + write("Current location of user: "+path+"\n"); + me->move(OBJ("/new1")); + write("Moving user to /new1\n"); + path = me->get_last_trail()->query_attribute("OBJ_PATH"); + write("New location of user: "+path+"\n"); + if(path=="/new1")pass=1; + string result = (pass==1)?"passed\n":"fail\n"; + write("Test case 1: move user - "+result); + me->move(OBJ("/home/root")); +} From 9016195eba65f1a038d9c791aeb1e6cbdcf091aa Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Thu, 7 Jul 2016 18:56:12 +0530 Subject: [PATCH 62/91] structural changes and added readme --- tests/coal-m4/Readme | 22 ++++++++++++++++++++++ {tools/tests => tests/coal-m4}/test | 0 {tools/tests => tests/coal-m4}/test.in | 0 tests/coal-pike/Readme | 2 ++ {tools/tests => tests/coal-pike}/test.pike | 0 5 files changed, 24 insertions(+) create mode 100644 tests/coal-m4/Readme rename {tools/tests => tests/coal-m4}/test (100%) rename {tools/tests => tests/coal-m4}/test.in (100%) create mode 100644 tests/coal-pike/Readme rename {tools/tests => tests/coal-pike}/test.pike (100%) diff --git a/tests/coal-m4/Readme b/tests/coal-m4/Readme new file mode 100644 index 0000000..343dda1 --- /dev/null +++ b/tests/coal-m4/Readme @@ -0,0 +1,22 @@ +The tests here use the pike scripts included to generate and run testsuites. + +mktestsuite +The mktestsuite script is a simple shell script that uses M4 to convert a testsuite input file into a testsuite that can be run by test_pike.pike. This script is found in $PIKE/include/pike. + +Usage: + +mktestsuite testsuite.in > testsuite + +The input file is simply a series of test invocations; any code outside of a test invocation will be ignored and will not appear in the final testsuite file. + + +test_pike + +The most important part of the regression testing infrastructure is test_pike, which is the pike script that performs the actual testing. Included in $PIKE/include/pike for Pike releases before 7.7, and as the builtin tool pike -x test_pike in releases 7.7 and higher, test_pike includes a large number of options for performing testing. + +Usage: + + pike -x test_pike testuitefile + +The first few cases are used to initialize the client and define global variables which are then used to execute tests. +We have written these initialization code as tests as there is no other way to execute simple pike code before running the tests. \ No newline at end of file diff --git a/tools/tests/test b/tests/coal-m4/test similarity index 100% rename from tools/tests/test rename to tests/coal-m4/test diff --git a/tools/tests/test.in b/tests/coal-m4/test.in similarity index 100% rename from tools/tests/test.in rename to tests/coal-m4/test.in diff --git a/tests/coal-pike/Readme b/tests/coal-pike/Readme new file mode 100644 index 0000000..a0ac151 --- /dev/null +++ b/tests/coal-pike/Readme @@ -0,0 +1,2 @@ +The tests in this folder are simple pike script. These scripts aim to develop its own testing framework. +To run the tests start the server and then execute the pike script in this folder. \ No newline at end of file diff --git a/tools/tests/test.pike b/tests/coal-pike/test.pike similarity index 100% rename from tools/tests/test.pike rename to tests/coal-pike/test.pike From efddba40525fd5b5a8122a9bc6575972505d22a8 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Thu, 7 Jul 2016 19:22:18 +0530 Subject: [PATCH 63/91] made the pike tests more modular --- tests/coal-pike/move.pike | 17 +++++++++++++++++ tests/coal-pike/test.pike | 13 ++----------- 2 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 tests/coal-pike/move.pike diff --git a/tests/coal-pike/move.pike b/tests/coal-pike/move.pike new file mode 100644 index 0000000..287ab7e --- /dev/null +++ b/tests/coal-pike/move.pike @@ -0,0 +1,17 @@ +#define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) + +int testcase_move(object me,object _Server) +{ + int pass = 0; + me->move(OBJ("/home/root")); + string oldpath = me->get_last_trail()->query_attribute("OBJ_PATH"); + write("Current location of user: "+oldpath+"\n"); + me->move(OBJ("/new1")); + write("Moving user to /new1\n"); + string newpath = me->get_last_trail()->query_attribute("OBJ_PATH"); + write("New location of user: "+newpath+"\n"); + if(newpath=="/new1" && oldpath=="/home/root")pass=1; + string result = (pass==1)?"passed\n":"fail\n"; + me->move(OBJ("/home/root")); + return pass; +} \ No newline at end of file diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index afdd245..9323a4b 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -22,15 +22,6 @@ void init(){ int main(){ init(); - int pass = 0; - string path = me->get_last_trail()->query_attribute("OBJ_PATH"); - write("Current location of user: "+path+"\n"); - me->move(OBJ("/new1")); - write("Moving user to /new1\n"); - path = me->get_last_trail()->query_attribute("OBJ_PATH"); - write("New location of user: "+path+"\n"); - if(path=="/new1")pass=1; - string result = (pass==1)?"passed\n":"fail\n"; - write("Test case 1: move user - "+result); - me->move(OBJ("/home/root")); + object test1 = ((program)"move.pike")(); + int res = test1->testcase_move(me,_Server); } From a318f5dec06c8d27d6bc030786a351a52393c190 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Thu, 7 Jul 2016 23:45:33 +0530 Subject: [PATCH 64/91] structural changes to testing framework using pike scripts --- tests/coal-m4/Readme | 4 +- tests/coal-pike/.test.pike.swp | Bin 0 -> 12288 bytes tests/coal-pike/move.pike | 2 +- tests/coal-pike/test.pike | 69 +++++++++++++++++++++++---------- 4 files changed, 52 insertions(+), 23 deletions(-) create mode 100644 tests/coal-pike/.test.pike.swp diff --git a/tests/coal-m4/Readme b/tests/coal-m4/Readme index 343dda1..b23cf9c 100644 --- a/tests/coal-m4/Readme +++ b/tests/coal-m4/Readme @@ -5,7 +5,7 @@ The mktestsuite script is a simple shell script that uses M4 to convert a testsu Usage: -mktestsuite testsuite.in > testsuite +mktestsuite test.in > test The input file is simply a series of test invocations; any code outside of a test invocation will be ignored and will not appear in the final testsuite file. @@ -16,7 +16,7 @@ The most important part of the regression testing infrastructure is test_pike, w Usage: - pike -x test_pike testuitefile + pike -x test_pike test The first few cases are used to initialize the client and define global variables which are then used to execute tests. We have written these initialization code as tests as there is no other way to execute simple pike code before running the tests. \ No newline at end of file diff --git a/tests/coal-pike/.test.pike.swp b/tests/coal-pike/.test.pike.swp new file mode 100644 index 0000000000000000000000000000000000000000..4b371b383cea478928391fd7e26b1296dac80f0b GIT binary patch literal 12288 zcmeI2zmMER6vyX~QW%neprLe}0k0XbknC9q2dINwwagdih`iOn?b60Vco%m;e)a;0fFo zNfPMNg_W}5Zb&bdj`|ZirP8WtVb&@xRBw7sRclps#$;}0dn$F_7Cv#js?4I2MJFQj z<~`J?6T>#3c7IaUWz)KjQA4@~C%TRs`=~d9DWyD}R2Uka^$UzvGK_1Ml>ce@Ay?<4M`qXA@9$y@QfE>ovX z*$I&b@?OilRyL;4RN#gMwGW{vJ%GTvN|%eUL}w`r6?P-f2fht;LbLCSMelCdg6>Zi z%7K1X=PHhBt126H`jgz4oAoM=Dq~#K#Bc54nVPcfPp&zu2%T+b3eOSHsjozP^!X!P80NVnP%Xr9P*bm8J)h|efO=i2Bj z)TMU+EiB(4zh)1>L*^97sn{7O^B4WjK)+jRJD_#COFx^z(n^u-W+|hmM>%cz?)%j| zmpZTUAc3RbJ+#XyW+!YS<9_?>Xa;Yu+a-+7tq5b0=F-~cIe{mFe;yp(Gp##qy}Q2F wNmnC*yWSKTBb?9FT$d`mdihFhI``gZbDb+%pU=BWDcWz;m^w4{q2MR}1%nOiRR910 literal 0 HcmV?d00001 diff --git a/tests/coal-pike/move.pike b/tests/coal-pike/move.pike index 287ab7e..109a3e1 100644 --- a/tests/coal-pike/move.pike +++ b/tests/coal-pike/move.pike @@ -1,6 +1,6 @@ #define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) -int testcase_move(object me,object _Server) +int testcase1(object me,object _Server) { int pass = 0; me->move(OBJ("/home/root")); diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index 9323a4b..c6161c6 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -1,27 +1,56 @@ #define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) -object _Server; -object me; - -void init(){ - string host = "127.0.0.1"; - int port = 1900; - string server_path = "/usr/local/lib/steam"; - master()->add_include_path(server_path+"/server/include"); - master()->add_program_path(server_path+"/server/"); - master()->add_program_path(server_path+"/conf/"); - master()->add_program_path(server_path+"/spm/"); - master()->add_program_path(server_path+"/server/net/coal/"); - object conn = ((program)"../spm/client_base.pike")(); - conn->connect_server(host,port); - conn->login("root","steam",1); - _Server = conn->SteamObj(0); - me = _Server->get_module("users")->lookup("root"); +class Testcase{ + string status; + object code; + int run(){ + + } +} +class Test{ + string name; + object _Server; + object me; + array(Testcase) cases; + int failures; + void create(string name,int totalCases){ + this.name=name; + cases = allocate(totalCases); + init(); + } + void init(){ + string host = "127.0.0.1"; + int port = 1900; + string server_path = "/usr/local/lib/steam"; + master()->add_include_path(server_path+"/server/include"); + master()->add_program_path(server_path+"/server/"); + master()->add_program_path(server_path+"/conf/"); + master()->add_program_path(server_path+"/spm/"); + master()->add_program_path(server_path+"/server/net/coal/"); + object conn = ((program)"../spm/client_base.pike")(); + conn->connect_server(host,port); + conn->login("root","steam",1); + _Server = conn->SteamObj(0); + me = _Server->get_module("users")->lookup("root"); + } + int run(){ + string n = name +".pike"; + object code = ((program)n)(); + array(function) foo = values(code); +// code->testcase1(me,_Server); + for(int i=0;i< sizeof(cases);i++){ + // code->testcase+"i"(); + foo[i](me,_Server); + } + } } + + int main(){ - init(); - object test1 = ((program)"move.pike")(); - int res = test1->testcase_move(me,_Server); + Test move = Test("move",1); + move->run(); +// object test1 = ((program)"move.pike")(); +// int res = test1->testcase_move(me,_Server); } From e4e02c095a1aaec7e06d6fac4c1100a1d17d7e5c Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Thu, 7 Jul 2016 23:46:30 +0530 Subject: [PATCH 65/91] removed swap files --- tests/coal-pike/.test.pike.swp | Bin 12288 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/coal-pike/.test.pike.swp diff --git a/tests/coal-pike/.test.pike.swp b/tests/coal-pike/.test.pike.swp deleted file mode 100644 index 4b371b383cea478928391fd7e26b1296dac80f0b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2zmMER6vyX~QW%neprLe}0k0XbknC9q2dINwwagdih`iOn?b60Vco%m;e)a;0fFo zNfPMNg_W}5Zb&bdj`|ZirP8WtVb&@xRBw7sRclps#$;}0dn$F_7Cv#js?4I2MJFQj z<~`J?6T>#3c7IaUWz)KjQA4@~C%TRs`=~d9DWyD}R2Uka^$UzvGK_1Ml>ce@Ay?<4M`qXA@9$y@QfE>ovX z*$I&b@?OilRyL;4RN#gMwGW{vJ%GTvN|%eUL}w`r6?P-f2fht;LbLCSMelCdg6>Zi z%7K1X=PHhBt126H`jgz4oAoM=Dq~#K#Bc54nVPcfPp&zu2%T+b3eOSHsjozP^!X!P80NVnP%Xr9P*bm8J)h|efO=i2Bj z)TMU+EiB(4zh)1>L*^97sn{7O^B4WjK)+jRJD_#COFx^z(n^u-W+|hmM>%cz?)%j| zmpZTUAc3RbJ+#XyW+!YS<9_?>Xa;Yu+a-+7tq5b0=F-~cIe{mFe;yp(Gp##qy}Q2F wNmnC*yWSKTBb?9FT$d`mdihFhI``gZbDb+%pU=BWDcWz;m^w4{q2MR}1%nOiRR910 From eebdb5d1882db375be7a81e63b91d261ed58bea8 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Sat, 9 Jul 2016 10:18:31 +0530 Subject: [PATCH 66/91] adding second test case --- tests/coal-pike/move.pike | 14 +++++++++++++- tests/coal-pike/test.pike | 6 +----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tests/coal-pike/move.pike b/tests/coal-pike/move.pike index 109a3e1..d5be1f0 100644 --- a/tests/coal-pike/move.pike +++ b/tests/coal-pike/move.pike @@ -14,4 +14,16 @@ int testcase1(object me,object _Server) string result = (pass==1)?"passed\n":"fail\n"; me->move(OBJ("/home/root")); return pass; -} \ No newline at end of file +} + +int testcase2(object me,object _Server) +{ + int pass = 0; + me->move("/home/root"); + string oldpath = me->get_last_trail()->query_attribute("OBJ_PATH"); + write("Current location of user: "+oldpath+"\n"); + mixed result = catch{me->move(OBJ("nopath"));}; + write("Moving to a non existential location nopath.\n"); + if(result ==0)pass=1; + return pass; +} diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index c6161c6..eafcf73 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -38,9 +38,7 @@ class Test{ string n = name +".pike"; object code = ((program)n)(); array(function) foo = values(code); -// code->testcase1(me,_Server); for(int i=0;i< sizeof(cases);i++){ - // code->testcase+"i"(); foo[i](me,_Server); } } @@ -49,8 +47,6 @@ class Test{ int main(){ - Test move = Test("move",1); + Test move = Test("move",2); move->run(); -// object test1 = ((program)"move.pike")(); -// int res = test1->testcase_move(me,_Server); } From 2dd71d1d1bf1632145b788ba6ce6bb62d8170043 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Sun, 10 Jul 2016 12:43:25 +0530 Subject: [PATCH 67/91] Add test cases for create --- tests/coal-pike/create.pike | 48 +++++++++++++++++++++++++++++++++++++ tests/coal-pike/test.pike | 12 ++++++++-- 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 tests/coal-pike/create.pike diff --git a/tests/coal-pike/create.pike b/tests/coal-pike/create.pike new file mode 100644 index 0000000..e325674 --- /dev/null +++ b/tests/coal-pike/create.pike @@ -0,0 +1,48 @@ +#define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) + +int testcase1(object me,object _Server) +{ + int pass = 0; + write ("creating a new Calendar\n"); + int result =_Server->get_factory("Calendar")->execute((["name":"TestCalendar"]))->move(OBJ(me->get_last_trail()->query_attribute("OBJ_PATH"))); + if(result == 1) pass = 1; +// if(pass == 1) +// OBJ(me->get_last_trail()->query_attribute("OBJ_PATH")+"/TestCalendar")->delete(); + return pass; +} + +int testcase2(object me,object _Server) +{ + int pass = 0; + write("creating a new Container\n"); + int result =_Server->get_factory("Container")->execute((["name":"TestContainer"]))->move(OBJ(me->get_last_trail()->query_attribute("OBJ_PATH"))); + if(result == 1) pass = 1; +// if(pass == 1) +// OBJ(me->get_last_trail()->query_attribute("OBJ_PATH")+"/TestContainer")->delete(); + return pass; + +} + +int testcase3(object me,object _Server) +{ + int pass = 0; + write("creating a new Date\n"); + int result =_Server->get_factory("Date")->execute((["name":"TestDate"]))->move(OBJ(me->get_last_trail()->query_attribute("OBJ_PATH"))); + if(result == 1) pass = 1; +// if(pass == 1) +// OBJ(me->get_last_trail()->query_attribute("OBJ_PATH")+"/TestDate")->delete(); + return pass; + +} + +int testcase4(object me,object _Server) +{ + int pass = 0; + write("creating a new Document\n"); + int result =_Server->get_factory("Document")->execute((["name":"TestDocument"]))->move(OBJ(me->get_last_trail()->query_attribute("OBJ_PATH"))); + if(result == 1) pass = 1; +// if(pass == 1) +// OBJ(me->get_last_trail()->query_attribute("OBJ_PATH")+"/TestDocument")->delete(); + return pass; + +} diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index eafcf73..048c261 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -19,6 +19,10 @@ class Test{ cases = allocate(totalCases); init(); } + void destroy(){ + me->move(OBJ("/home/steam")); + OBJ("/TestRoom")->delete(); + } void init(){ string host = "127.0.0.1"; int port = 1900; @@ -33,6 +37,10 @@ class Test{ conn->login("root","steam",1); _Server = conn->SteamObj(0); me = _Server->get_module("users")->lookup("root"); + me->move(OBJ("/")); + write("Creating test room\n\n"); + _Server->get_factory("Room")->execute((["name":"TestRoom"]))->move(OBJ("/")); + me->move(OBJ("/TestRoom")); } int run(){ string n = name +".pike"; @@ -47,6 +55,6 @@ class Test{ int main(){ - Test move = Test("move",2); - move->run(); + Test create = Test("create",4); + create->run(); } From 271fb169792001be54d8f5e47894371ad514f4fa Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Tue, 12 Jul 2016 15:10:13 +0530 Subject: [PATCH 68/91] Display the number of failed and passed cases --- tests/coal-pike/test.pike | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index eafcf73..71ef647 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -38,9 +38,11 @@ class Test{ string n = name +".pike"; object code = ((program)n)(); array(function) foo = values(code); + int success = 0; for(int i=0;i< sizeof(cases);i++){ - foo[i](me,_Server); + success += foo[i](me,_Server); } + write("success: "+success+"\nfails: "+(sizeof(cases)-success)+"\n"); } } From e68ecf33d4efb66cdc36a898cac33b7e74adaefd Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Tue, 12 Jul 2016 18:00:54 +0530 Subject: [PATCH 69/91] Removed the delete for indivisual objects --- tests/coal-pike/create.pike | 38 +++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/tests/coal-pike/create.pike b/tests/coal-pike/create.pike index e325674..e6d1502 100644 --- a/tests/coal-pike/create.pike +++ b/tests/coal-pike/create.pike @@ -4,10 +4,11 @@ int testcase1(object me,object _Server) { int pass = 0; write ("creating a new Calendar\n"); - int result =_Server->get_factory("Calendar")->execute((["name":"TestCalendar"]))->move(OBJ(me->get_last_trail()->query_attribute("OBJ_PATH"))); + object room = OBJ("/TestRoom"); + int result =_Server->get_factory("Calendar")->execute((["name":"TestCalendar"]))->move(room); if(result == 1) pass = 1; -// if(pass == 1) -// OBJ(me->get_last_trail()->query_attribute("OBJ_PATH")+"/TestCalendar")->delete(); + if(pass == 1) + OBJ("TestRoom/TestCalendar")->query_attribute("OBJ_NAME"); return pass; } @@ -15,10 +16,11 @@ int testcase2(object me,object _Server) { int pass = 0; write("creating a new Container\n"); - int result =_Server->get_factory("Container")->execute((["name":"TestContainer"]))->move(OBJ(me->get_last_trail()->query_attribute("OBJ_PATH"))); + object room = OBJ("/TestRoom"); + int result =_Server->get_factory("Container")->execute((["name":"TestContainer"]))->move(room); if(result == 1) pass = 1; -// if(pass == 1) -// OBJ(me->get_last_trail()->query_attribute("OBJ_PATH")+"/TestContainer")->delete(); + if(pass == 1) + OBJ("TestRoom/TestContainer")->query_attribute("OBJ_NAME"); return pass; } @@ -27,10 +29,11 @@ int testcase3(object me,object _Server) { int pass = 0; write("creating a new Date\n"); - int result =_Server->get_factory("Date")->execute((["name":"TestDate"]))->move(OBJ(me->get_last_trail()->query_attribute("OBJ_PATH"))); + object room = OBJ("/TestRoom"); + int result =_Server->get_factory("Date")->execute((["name":"TestDate"]))->move(room); if(result == 1) pass = 1; -// if(pass == 1) -// OBJ(me->get_last_trail()->query_attribute("OBJ_PATH")+"/TestDate")->delete(); + if(pass == 1) + OBJ("TestRoom/TestDate")->query_attribute("OBJ_NAME"); return pass; } @@ -39,10 +42,21 @@ int testcase4(object me,object _Server) { int pass = 0; write("creating a new Document\n"); - int result =_Server->get_factory("Document")->execute((["name":"TestDocument"]))->move(OBJ(me->get_last_trail()->query_attribute("OBJ_PATH"))); + object room = OBJ("/TestRoom"); + int result =_Server->get_factory("Document")->execute((["name":"TestDocument"]))->move(room); if(result == 1) pass = 1; -// if(pass == 1) -// OBJ(me->get_last_trail()->query_attribute("OBJ_PATH")+"/TestDocument")->delete(); + if(pass == 1) + OBJ("TestRoom/TestDocument")->query_attribute("OBJ_NAME"); return pass; } + +int testcase5(object me,object _Server) +{ + int pass=0; + write("Creating a class that does not exists\n"); + mixed result = _Server->get_factory("NoClass"); + if(result == 0) pass =1; + return pass; +} + From d0c607dae70e3b2885c147aff47f86724ec7ed84 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Wed, 13 Jul 2016 08:31:36 +0530 Subject: [PATCH 70/91] Added test case for moving user and room into a container. --- tests/coal-pike/.move.pike.swp | Bin 0 -> 12288 bytes tests/coal-pike/move.pike | 49 +++++++++++++++++++++++---------- tests/coal-pike/test.pike | 13 +++++++-- 3 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 tests/coal-pike/.move.pike.swp diff --git a/tests/coal-pike/.move.pike.swp b/tests/coal-pike/.move.pike.swp new file mode 100644 index 0000000000000000000000000000000000000000..91987aaa54a42c7ca510397f47fa9818bc2002f3 GIT binary patch literal 12288 zcmeI2J#W)M7{{+{0ow8+fsi^}T~KX_Hfd9Y)RGQ>gbFH1P+;ICxb~$r#JZ4UELI%h{e+C9wd3vg(%Z?eN{Pd~&{Z*qxf8&K^bZ`2WBC`+sMcvCrT=*aDm20{A(^*f;PAd;kG>2A+Z^;1Vc<^We`QV>@6Q zya6qsKm=}q1uzT7!B^}zcn7NB2H@Z%7zRV&*D=O^fbU=fjDX*W`3u+rF1QUUU>uwS zI;S&$4l+On$N(8217v^$gt-BwWL&efZyQCz}?(!1yOB#*bjmA2Rcp4RWcbQ7uC-Md*2KJ66HXJ!nU9RX_JuKP=&rjxKCw_J4!t)p!_w(y zcc25`zwIQv{C2%S#RCT)r8&0F^u69=>)4T)F;fG+xR_q0VOaQT-8=3DR_F~o_NgN% z>i~DngwDY8QS`ar&^IFyV(69Rc6ZRyq2Dv;zR2{pJAh;k=-g13SF&aHFwF4nwAVQaN#*LhuH0eN^B$cC*}C-W9r zZwyHV9e`eDd6`ZhD$|VF6g8LI6Molx>J6u}o|9$MHBvcXvh|;Fr;GTa6I3D~dup}A z&VC29o5-J6d1|Nf)Q-8LhWBy&zLOU3iO`pBvyK;T&8rJN@UtouLN8c-Q&qB>tb0>h F>@S>#DA)i1 literal 0 HcmV?d00001 diff --git a/tests/coal-pike/move.pike b/tests/coal-pike/move.pike index d5be1f0..e47d1c8 100644 --- a/tests/coal-pike/move.pike +++ b/tests/coal-pike/move.pike @@ -3,27 +3,48 @@ int testcase1(object me,object _Server) { int pass = 0; - me->move(OBJ("/home/root")); - string oldpath = me->get_last_trail()->query_attribute("OBJ_PATH"); - write("Current location of user: "+oldpath+"\n"); - me->move(OBJ("/new1")); - write("Moving user to /new1\n"); - string newpath = me->get_last_trail()->query_attribute("OBJ_PATH"); - write("New location of user: "+newpath+"\n"); - if(newpath=="/new1" && oldpath=="/home/root")pass=1; - string result = (pass==1)?"passed\n":"fail\n"; - me->move(OBJ("/home/root")); + _Server->get_factory("Room")->execute((["name":"TestsubRoom"]))->move(OBJ("/TestRoom")); + mixed result = catch{me->move(OBJ("/TestRoom/TestsubRoom"));}; + write("Moving user\n"); + if(result == 0)pass=1; + me->move(OBJ("/TestRoom")); + OBJ("/TestRoom/TestsubRoom")->delete(); return pass; } int testcase2(object me,object _Server) { int pass = 0; - me->move("/home/root"); - string oldpath = me->get_last_trail()->query_attribute("OBJ_PATH"); - write("Current location of user: "+oldpath+"\n"); mixed result = catch{me->move(OBJ("nopath"));}; write("Moving to a non existential location nopath.\n"); - if(result ==0)pass=1; + if(result !=0)pass=1; + me->move(OBJ("/TestRoom")); + return pass; +} + +int testcase3(object me,object _Server) +{ + int pass = 0; + mixed result = 0; + int res =_Server->get_factory("Container")->execute((["name":"Testmove3"]))->move(OBJ("/TestRoom")); + result = catch{me->move(OBJ("/TestRoom/Testmove3"));}; + write("Moving user into a container\n"); + if(result != 0)pass=1; + OBJ("/TestRoom/Testmove3")->delete(); + return pass; +} + +int testcase4(object me,object _Server) +{ + int pass = 0; + _Server->get_factory("Room")->execute((["name":"Testmove4"]))->move(OBJ("/TestRoom")); + _Server->get_factory("Container")->execute((["name":"Testcontmove4"]))->move(OBJ("/TestRoom")); + object room = OBJ("/TestRoom/Testmove4"); + object container = OBJ("/TestRoom/Testcontmove4"); + mixed result = catch{room->move(container);}; + write("Moving room inside container\n"); + if(result!=0)pass=1; + room->delete(); + container->delete(); return pass; } diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index 71ef647..a2a35e2 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -19,6 +19,10 @@ class Test{ cases = allocate(totalCases); init(); } + void destroy(){ + me->move(OBJ("/home/steam")); + OBJ("/TestRoom")->delete(); + } void init(){ string host = "127.0.0.1"; int port = 1900; @@ -33,6 +37,8 @@ class Test{ conn->login("root","steam",1); _Server = conn->SteamObj(0); me = _Server->get_module("users")->lookup("root"); + _Server->get_factory("Room")->execute((["name":"TestRoom"]))->move(OBJ("/")); + me->move(OBJ("/TestRoom")); } int run(){ string n = name +".pike"; @@ -40,7 +46,10 @@ class Test{ array(function) foo = values(code); int success = 0; for(int i=0;i< sizeof(cases);i++){ - success += foo[i](me,_Server); + if(foo[i](me,_Server)==1){ + success+=1; + } + } write("success: "+success+"\nfails: "+(sizeof(cases)-success)+"\n"); } @@ -49,6 +58,6 @@ class Test{ int main(){ - Test move = Test("move",2); + Test move = Test("move",4); move->run(); } From 8ddfb75477d0895cd759feb1b40b232c12f402f7 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Wed, 13 Jul 2016 08:34:32 +0530 Subject: [PATCH 71/91] Added test cases for moving user and room inside container. --- tests/coal-pike/.move.pike.swp | Bin 0 -> 12288 bytes tests/coal-pike/move.pike | 49 +++++++++++++++++++++++---------- tests/coal-pike/test.pike | 13 +++++++-- 3 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 tests/coal-pike/.move.pike.swp diff --git a/tests/coal-pike/.move.pike.swp b/tests/coal-pike/.move.pike.swp new file mode 100644 index 0000000000000000000000000000000000000000..91987aaa54a42c7ca510397f47fa9818bc2002f3 GIT binary patch literal 12288 zcmeI2J#W)M7{{+{0ow8+fsi^}T~KX_Hfd9Y)RGQ>gbFH1P+;ICxb~$r#JZ4UELI%h{e+C9wd3vg(%Z?eN{Pd~&{Z*qxf8&K^bZ`2WBC`+sMcvCrT=*aDm20{A(^*f;PAd;kG>2A+Z^;1Vc<^We`QV>@6Q zya6qsKm=}q1uzT7!B^}zcn7NB2H@Z%7zRV&*D=O^fbU=fjDX*W`3u+rF1QUUU>uwS zI;S&$4l+On$N(8217v^$gt-BwWL&efZyQCz}?(!1yOB#*bjmA2Rcp4RWcbQ7uC-Md*2KJ66HXJ!nU9RX_JuKP=&rjxKCw_J4!t)p!_w(y zcc25`zwIQv{C2%S#RCT)r8&0F^u69=>)4T)F;fG+xR_q0VOaQT-8=3DR_F~o_NgN% z>i~DngwDY8QS`ar&^IFyV(69Rc6ZRyq2Dv;zR2{pJAh;k=-g13SF&aHFwF4nwAVQaN#*LhuH0eN^B$cC*}C-W9r zZwyHV9e`eDd6`ZhD$|VF6g8LI6Molx>J6u}o|9$MHBvcXvh|;Fr;GTa6I3D~dup}A z&VC29o5-J6d1|Nf)Q-8LhWBy&zLOU3iO`pBvyK;T&8rJN@UtouLN8c-Q&qB>tb0>h F>@S>#DA)i1 literal 0 HcmV?d00001 diff --git a/tests/coal-pike/move.pike b/tests/coal-pike/move.pike index d5be1f0..e47d1c8 100644 --- a/tests/coal-pike/move.pike +++ b/tests/coal-pike/move.pike @@ -3,27 +3,48 @@ int testcase1(object me,object _Server) { int pass = 0; - me->move(OBJ("/home/root")); - string oldpath = me->get_last_trail()->query_attribute("OBJ_PATH"); - write("Current location of user: "+oldpath+"\n"); - me->move(OBJ("/new1")); - write("Moving user to /new1\n"); - string newpath = me->get_last_trail()->query_attribute("OBJ_PATH"); - write("New location of user: "+newpath+"\n"); - if(newpath=="/new1" && oldpath=="/home/root")pass=1; - string result = (pass==1)?"passed\n":"fail\n"; - me->move(OBJ("/home/root")); + _Server->get_factory("Room")->execute((["name":"TestsubRoom"]))->move(OBJ("/TestRoom")); + mixed result = catch{me->move(OBJ("/TestRoom/TestsubRoom"));}; + write("Moving user\n"); + if(result == 0)pass=1; + me->move(OBJ("/TestRoom")); + OBJ("/TestRoom/TestsubRoom")->delete(); return pass; } int testcase2(object me,object _Server) { int pass = 0; - me->move("/home/root"); - string oldpath = me->get_last_trail()->query_attribute("OBJ_PATH"); - write("Current location of user: "+oldpath+"\n"); mixed result = catch{me->move(OBJ("nopath"));}; write("Moving to a non existential location nopath.\n"); - if(result ==0)pass=1; + if(result !=0)pass=1; + me->move(OBJ("/TestRoom")); + return pass; +} + +int testcase3(object me,object _Server) +{ + int pass = 0; + mixed result = 0; + int res =_Server->get_factory("Container")->execute((["name":"Testmove3"]))->move(OBJ("/TestRoom")); + result = catch{me->move(OBJ("/TestRoom/Testmove3"));}; + write("Moving user into a container\n"); + if(result != 0)pass=1; + OBJ("/TestRoom/Testmove3")->delete(); + return pass; +} + +int testcase4(object me,object _Server) +{ + int pass = 0; + _Server->get_factory("Room")->execute((["name":"Testmove4"]))->move(OBJ("/TestRoom")); + _Server->get_factory("Container")->execute((["name":"Testcontmove4"]))->move(OBJ("/TestRoom")); + object room = OBJ("/TestRoom/Testmove4"); + object container = OBJ("/TestRoom/Testcontmove4"); + mixed result = catch{room->move(container);}; + write("Moving room inside container\n"); + if(result!=0)pass=1; + room->delete(); + container->delete(); return pass; } diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index 71ef647..a2a35e2 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -19,6 +19,10 @@ class Test{ cases = allocate(totalCases); init(); } + void destroy(){ + me->move(OBJ("/home/steam")); + OBJ("/TestRoom")->delete(); + } void init(){ string host = "127.0.0.1"; int port = 1900; @@ -33,6 +37,8 @@ class Test{ conn->login("root","steam",1); _Server = conn->SteamObj(0); me = _Server->get_module("users")->lookup("root"); + _Server->get_factory("Room")->execute((["name":"TestRoom"]))->move(OBJ("/")); + me->move(OBJ("/TestRoom")); } int run(){ string n = name +".pike"; @@ -40,7 +46,10 @@ class Test{ array(function) foo = values(code); int success = 0; for(int i=0;i< sizeof(cases);i++){ - success += foo[i](me,_Server); + if(foo[i](me,_Server)==1){ + success+=1; + } + } write("success: "+success+"\nfails: "+(sizeof(cases)-success)+"\n"); } @@ -49,6 +58,6 @@ class Test{ int main(){ - Test move = Test("move",2); + Test move = Test("move",4); move->run(); } From deb8d59a95a83358a5a2497a099ed4b05ebfdc61 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Thu, 14 Jul 2016 18:41:07 +0530 Subject: [PATCH 72/91] Generalized the test case to pass any object to a test --- tests/coal-pike/.move.pike.swp | Bin 12288 -> 0 bytes tests/coal-pike/move.pike | 34 +++++++++++++++++++---- tests/coal-pike/move_nonexistential.pike | 9 ++++++ 3 files changed, 38 insertions(+), 5 deletions(-) delete mode 100644 tests/coal-pike/.move.pike.swp create mode 100644 tests/coal-pike/move_nonexistential.pike diff --git a/tests/coal-pike/.move.pike.swp b/tests/coal-pike/.move.pike.swp deleted file mode 100644 index 91987aaa54a42c7ca510397f47fa9818bc2002f3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2J#W)M7{{+{0ow8+fsi^}T~KX_Hfd9Y)RGQ>gbFH1P+;ICxb~$r#JZ4UELI%h{e+C9wd3vg(%Z?eN{Pd~&{Z*qxf8&K^bZ`2WBC`+sMcvCrT=*aDm20{A(^*f;PAd;kG>2A+Z^;1Vc<^We`QV>@6Q zya6qsKm=}q1uzT7!B^}zcn7NB2H@Z%7zRV&*D=O^fbU=fjDX*W`3u+rF1QUUU>uwS zI;S&$4l+On$N(8217v^$gt-BwWL&efZyQCz}?(!1yOB#*bjmA2Rcp4RWcbQ7uC-Md*2KJ66HXJ!nU9RX_JuKP=&rjxKCw_J4!t)p!_w(y zcc25`zwIQv{C2%S#RCT)r8&0F^u69=>)4T)F;fG+xR_q0VOaQT-8=3DR_F~o_NgN% z>i~DngwDY8QS`ar&^IFyV(69Rc6ZRyq2Dv;zR2{pJAh;k=-g13SF&aHFwF4nwAVQaN#*LhuH0eN^B$cC*}C-W9r zZwyHV9e`eDd6`ZhD$|VF6g8LI6Molx>J6u}o|9$MHBvcXvh|;Fr;GTa6I3D~dup}A z&VC29o5-J6d1|Nf)Q-8LhWBy&zLOU3iO`pBvyK;T&8rJN@UtouLN8c-Q&qB>tb0>h F>@S>#DA)i1 diff --git a/tests/coal-pike/move.pike b/tests/coal-pike/move.pike index e47d1c8..84b9068 100644 --- a/tests/coal-pike/move.pike +++ b/tests/coal-pike/move.pike @@ -5,22 +5,42 @@ int testcase1(object me,object _Server) int pass = 0; _Server->get_factory("Room")->execute((["name":"TestsubRoom"]))->move(OBJ("/TestRoom")); mixed result = catch{me->move(OBJ("/TestRoom/TestsubRoom"));}; - write("Moving user\n"); + write("Moving user: "); if(result == 0)pass=1; + if(pass==1)write("passed\n"); + else write("failed\n"); me->move(OBJ("/TestRoom")); OBJ("/TestRoom/TestsubRoom")->delete(); return pass; } - +/* int testcase2(object me,object _Server) { int pass = 0; mixed result = catch{me->move(OBJ("nopath"));}; - write("Moving to a non existential location nopath.\n"); + write("Moving to a non existential location nopath.: "); if(result !=0)pass=1; + if(pass==1)write("passed\n"); + else write("failed\n"); me->move(OBJ("/TestRoom")); return pass; } +*/ + +int testcase2(object me,object _Server) +{ + int pass = 1; + object code = ((program)"move_nonexistential.pike")(); + array(function) foo = values(code); + _Server->get_factory("Room")->execute((["name":"move2Room"]))->move(OBJ("/TestRoom")); + int success = foo[0](me,_Server,OBJ("/TestRoom/move2Room")); + write("Moving room to a non existential path: "); + if(success==0)pass=0; + if(pass == 1)write("passed\n"); + else write("failed\n"); + OBJ("/TestRoom/move2Room")->delete(); + return pass; +} int testcase3(object me,object _Server) { @@ -28,8 +48,10 @@ int testcase3(object me,object _Server) mixed result = 0; int res =_Server->get_factory("Container")->execute((["name":"Testmove3"]))->move(OBJ("/TestRoom")); result = catch{me->move(OBJ("/TestRoom/Testmove3"));}; - write("Moving user into a container\n"); + write("Moving user into a container: "); if(result != 0)pass=1; + if(pass==1)write("passed\n"); + else write("failed\n"); OBJ("/TestRoom/Testmove3")->delete(); return pass; } @@ -42,8 +64,10 @@ int testcase4(object me,object _Server) object room = OBJ("/TestRoom/Testmove4"); object container = OBJ("/TestRoom/Testcontmove4"); mixed result = catch{room->move(container);}; - write("Moving room inside container\n"); + write("Moving room inside container: "); if(result!=0)pass=1; + if(pass==1)write("passed\n"); + else write("failed\n"); room->delete(); container->delete(); return pass; diff --git a/tests/coal-pike/move_nonexistential.pike b/tests/coal-pike/move_nonexistential.pike new file mode 100644 index 0000000..f02905a --- /dev/null +++ b/tests/coal-pike/move_nonexistential.pike @@ -0,0 +1,9 @@ +#define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) + +int testcase(object me,object _Server,object x) +{ + int pass = 0; + mixed result = catch{x->move(OBJ("non-existential-path"));}; + if(result!=0)pass=1; + return pass; +} From 8981b85a54ea35618cf759244095d84cb7128943 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Sun, 17 Jul 2016 17:03:07 +0530 Subject: [PATCH 73/91] Added checks to avoid calling functions on non objects --- tests/coal-pike/move.pike | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/tests/coal-pike/move.pike b/tests/coal-pike/move.pike index 84b9068..a40a52f 100644 --- a/tests/coal-pike/move.pike +++ b/tests/coal-pike/move.pike @@ -4,13 +4,14 @@ int testcase1(object me,object _Server) { int pass = 0; _Server->get_factory("Room")->execute((["name":"TestsubRoom"]))->move(OBJ("/TestRoom")); - mixed result = catch{me->move(OBJ("/TestRoom/TestsubRoom"));}; + object obj = OBJ("/TestRoom/TestsubRoom"); + mixed result = catch{me->move(obj);}; write("Moving user: "); if(result == 0)pass=1; if(pass==1)write("passed\n"); else write("failed\n"); me->move(OBJ("/TestRoom")); - OBJ("/TestRoom/TestsubRoom")->delete(); + if(obj!=0)obj->delete(); return pass; } /* @@ -33,12 +34,27 @@ int testcase2(object me,object _Server) object code = ((program)"move_nonexistential.pike")(); array(function) foo = values(code); _Server->get_factory("Room")->execute((["name":"move2Room"]))->move(OBJ("/TestRoom")); - int success = foo[0](me,_Server,OBJ("/TestRoom/move2Room")); - write("Moving room to a non existential path: "); + _Server->get_factory("User")->execute((["name":"move2User","pw":"testpass","email":"abc@example.com"])); + _Server->get_module("users")->get_user("move2User")->activate_user(); + array(object) testObjects = allocate(2); + do{ + testObjects[0]=OBJ("/TestRoom/move2Room"); + }while(testObjects[0]==0); + do{ + testObjects[1]=_Server->get_module("users")->get_user("move2User"); + }while(testObjects[1]==0); + int success = 1; + for(int i = 0;iget_class()+ " to a non existential path: "); + int ctr = foo[0](me,_Server,testObjects[i]); + if(ctr == 0)success =0; + if(success == 1)write("passed\n"); + else write("failed\n"); + } + if(success==0)pass=0; - if(pass == 1)write("passed\n"); - else write("failed\n"); - OBJ("/TestRoom/move2Room")->delete(); + if(testObjects[1]!=0) + testObjects[1]->delete(); return pass; } @@ -47,12 +63,13 @@ int testcase3(object me,object _Server) int pass = 0; mixed result = 0; int res =_Server->get_factory("Container")->execute((["name":"Testmove3"]))->move(OBJ("/TestRoom")); - result = catch{me->move(OBJ("/TestRoom/Testmove3"));}; + object obj = OBJ("/TestRoom/Testmove3"); + result = catch{me->move(obj);}; write("Moving user into a container: "); if(result != 0)pass=1; if(pass==1)write("passed\n"); else write("failed\n"); - OBJ("/TestRoom/Testmove3")->delete(); + if(obj!=0)obj->delete(); return pass; } @@ -68,7 +85,9 @@ int testcase4(object me,object _Server) if(result!=0)pass=1; if(pass==1)write("passed\n"); else write("failed\n"); + if(room!=0) room->delete(); + if(container!=0) container->delete(); return pass; } From 14a952aae56433b96bee63c8a2c5e618362dcf6f Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Mon, 18 Jul 2016 17:37:23 +0530 Subject: [PATCH 74/91] Added the test cases for create --- tests/coal-pike/create.pike | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tests/coal-pike/create.pike diff --git a/tests/coal-pike/create.pike b/tests/coal-pike/create.pike new file mode 100644 index 0000000..e6d1502 --- /dev/null +++ b/tests/coal-pike/create.pike @@ -0,0 +1,62 @@ +#define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) + +int testcase1(object me,object _Server) +{ + int pass = 0; + write ("creating a new Calendar\n"); + object room = OBJ("/TestRoom"); + int result =_Server->get_factory("Calendar")->execute((["name":"TestCalendar"]))->move(room); + if(result == 1) pass = 1; + if(pass == 1) + OBJ("TestRoom/TestCalendar")->query_attribute("OBJ_NAME"); + return pass; +} + +int testcase2(object me,object _Server) +{ + int pass = 0; + write("creating a new Container\n"); + object room = OBJ("/TestRoom"); + int result =_Server->get_factory("Container")->execute((["name":"TestContainer"]))->move(room); + if(result == 1) pass = 1; + if(pass == 1) + OBJ("TestRoom/TestContainer")->query_attribute("OBJ_NAME"); + return pass; + +} + +int testcase3(object me,object _Server) +{ + int pass = 0; + write("creating a new Date\n"); + object room = OBJ("/TestRoom"); + int result =_Server->get_factory("Date")->execute((["name":"TestDate"]))->move(room); + if(result == 1) pass = 1; + if(pass == 1) + OBJ("TestRoom/TestDate")->query_attribute("OBJ_NAME"); + return pass; + +} + +int testcase4(object me,object _Server) +{ + int pass = 0; + write("creating a new Document\n"); + object room = OBJ("/TestRoom"); + int result =_Server->get_factory("Document")->execute((["name":"TestDocument"]))->move(room); + if(result == 1) pass = 1; + if(pass == 1) + OBJ("TestRoom/TestDocument")->query_attribute("OBJ_NAME"); + return pass; + +} + +int testcase5(object me,object _Server) +{ + int pass=0; + write("Creating a class that does not exists\n"); + mixed result = _Server->get_factory("NoClass"); + if(result == 0) pass =1; + return pass; +} + From d4de0f20e5f69271cd43917a9a68bf4753846eae Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Mon, 18 Jul 2016 17:39:06 +0530 Subject: [PATCH 75/91] Added function calls for create in the framework --- tests/coal-pike/test.pike | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index a2a35e2..95df5c8 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -60,4 +60,6 @@ class Test{ int main(){ Test move = Test("move",4); move->run(); + Test create = Test("create",5); + create->run(); } From bb1d4b5c59ec99b74a308230ccf8b4695d699ed2 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Mon, 18 Jul 2016 19:44:30 +0530 Subject: [PATCH 76/91] Generalized the test case for create and combined the create and move testcases in the framework --- tests/coal-pike/create.pike | 39 +++++++++++++++++++++++------- tests/coal-pike/create_object.pike | 13 ++++++++++ tests/coal-pike/move.pike | 2 +- tests/coal-pike/test.pike | 6 +++-- 4 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 tests/coal-pike/create_object.pike diff --git a/tests/coal-pike/create.pike b/tests/coal-pike/create.pike index e6d1502..e6bdb6a 100644 --- a/tests/coal-pike/create.pike +++ b/tests/coal-pike/create.pike @@ -1,5 +1,22 @@ #define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) +int testcase1(object me,object _Server) +{ + object code = ((program)"create_object.pike")(); + array(function) foo = values(code); + int success = 1; + array(string) testClass = ({"Container","Document","Room"}); + for(int i =0;iget_factory("Calendar")->execute((["name":"TestCalendar"]))->move(room); if(result == 1) pass = 1; - if(pass == 1) - OBJ("TestRoom/TestCalendar")->query_attribute("OBJ_NAME"); + object obj = OBJ("TestRoom/TestCalendar"); + if(obj!=0) + obj->delete(); return pass; } @@ -18,9 +36,10 @@ int testcase2(object me,object _Server) write("creating a new Container\n"); object room = OBJ("/TestRoom"); int result =_Server->get_factory("Container")->execute((["name":"TestContainer"]))->move(room); + object obj = OBJ("TestRoom/TestContainer"); if(result == 1) pass = 1; - if(pass == 1) - OBJ("TestRoom/TestContainer")->query_attribute("OBJ_NAME"); + if(obj != 0) + obj->delete(); return pass; } @@ -32,8 +51,9 @@ int testcase3(object me,object _Server) object room = OBJ("/TestRoom"); int result =_Server->get_factory("Date")->execute((["name":"TestDate"]))->move(room); if(result == 1) pass = 1; - if(pass == 1) - OBJ("TestRoom/TestDate")->query_attribute("OBJ_NAME"); + object obj = OBJ("TestRoom/TestDate"); + if(obj != 0) + obj->delete(); return pass; } @@ -44,13 +64,14 @@ int testcase4(object me,object _Server) write("creating a new Document\n"); object room = OBJ("/TestRoom"); int result =_Server->get_factory("Document")->execute((["name":"TestDocument"]))->move(room); + object obj = OBJ("TestRoom/TestDocument"); if(result == 1) pass = 1; - if(pass == 1) - OBJ("TestRoom/TestDocument")->query_attribute("OBJ_NAME"); + if(obj != 0) + obj->delete(); return pass; } - +*/ int testcase5(object me,object _Server) { int pass=0; diff --git a/tests/coal-pike/create_object.pike b/tests/coal-pike/create_object.pike new file mode 100644 index 0000000..7f156b6 --- /dev/null +++ b/tests/coal-pike/create_object.pike @@ -0,0 +1,13 @@ +#define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) + +int testcase(object me,object _Server,string type) +{ + int pass = 0; + object room = OBJ("/TestRoom"); + mixed result =catch{ _Server->get_factory(type)->execute((["name":"TestObj"+type]))->move(room); }; + if(result ==0)pass=1; + object ref = OBJ("/TestRoom/TestObj"); + if(ref!=0)ref->delete(); + return pass; + +} diff --git a/tests/coal-pike/move.pike b/tests/coal-pike/move.pike index a40a52f..773afad 100644 --- a/tests/coal-pike/move.pike +++ b/tests/coal-pike/move.pike @@ -48,7 +48,7 @@ int testcase2(object me,object _Server) write("Moving "+testObjects[i]->get_class()+ " to a non existential path: "); int ctr = foo[0](me,_Server,testObjects[i]); if(ctr == 0)success =0; - if(success == 1)write("passed\n"); + if(ctr == 1)write("passed\n"); else write("failed\n"); } diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index 95df5c8..12f3243 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -21,7 +21,9 @@ class Test{ } void destroy(){ me->move(OBJ("/home/steam")); - OBJ("/TestRoom")->delete(); + object obj = OBJ("/TestRoom"); + if(obj!=0) + obj->delete(); } void init(){ string host = "127.0.0.1"; @@ -60,6 +62,6 @@ class Test{ int main(){ Test move = Test("move",4); move->run(); - Test create = Test("create",5); + Test create = Test("create",2); create->run(); } From 96e9aea2b8a5292b42fbba66a618af696d3dc4bd Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Tue, 19 Jul 2016 18:44:48 +0530 Subject: [PATCH 77/91] Added support for testing creation of user and groups --- tests/coal-pike/create.pike | 61 ++---------------------------- tests/coal-pike/create_object.pike | 1 + 2 files changed, 4 insertions(+), 58 deletions(-) diff --git a/tests/coal-pike/create.pike b/tests/coal-pike/create.pike index e6bdb6a..0529170 100644 --- a/tests/coal-pike/create.pike +++ b/tests/coal-pike/create.pike @@ -5,74 +5,18 @@ int testcase1(object me,object _Server) object code = ((program)"create_object.pike")(); array(function) foo = values(code); int success = 1; - array(string) testClass = ({"Container","Document","Room"}); + array(string) testClass = ({"Container","Document","Room","Exit","User","Group"}); for(int i =0;iget_factory("Calendar")->execute((["name":"TestCalendar"]))->move(room); - if(result == 1) pass = 1; - object obj = OBJ("TestRoom/TestCalendar"); - if(obj!=0) - obj->delete(); - return pass; -} - int testcase2(object me,object _Server) -{ - int pass = 0; - write("creating a new Container\n"); - object room = OBJ("/TestRoom"); - int result =_Server->get_factory("Container")->execute((["name":"TestContainer"]))->move(room); - object obj = OBJ("TestRoom/TestContainer"); - if(result == 1) pass = 1; - if(obj != 0) - obj->delete(); - return pass; - -} - -int testcase3(object me,object _Server) -{ - int pass = 0; - write("creating a new Date\n"); - object room = OBJ("/TestRoom"); - int result =_Server->get_factory("Date")->execute((["name":"TestDate"]))->move(room); - if(result == 1) pass = 1; - object obj = OBJ("TestRoom/TestDate"); - if(obj != 0) - obj->delete(); - return pass; - -} - -int testcase4(object me,object _Server) -{ - int pass = 0; - write("creating a new Document\n"); - object room = OBJ("/TestRoom"); - int result =_Server->get_factory("Document")->execute((["name":"TestDocument"]))->move(room); - object obj = OBJ("TestRoom/TestDocument"); - if(result == 1) pass = 1; - if(obj != 0) - obj->delete(); - return pass; - -} -*/ -int testcase5(object me,object _Server) { int pass=0; write("Creating a class that does not exists\n"); @@ -81,3 +25,4 @@ int testcase5(object me,object _Server) return pass; } + diff --git a/tests/coal-pike/create_object.pike b/tests/coal-pike/create_object.pike index 7f156b6..70f9c7c 100644 --- a/tests/coal-pike/create_object.pike +++ b/tests/coal-pike/create_object.pike @@ -6,6 +6,7 @@ int testcase(object me,object _Server,string type) object room = OBJ("/TestRoom"); mixed result =catch{ _Server->get_factory(type)->execute((["name":"TestObj"+type]))->move(room); }; if(result ==0)pass=1; + else if((type=="User"||type=="Group")&& result!=0)pass=1; object ref = OBJ("/TestRoom/TestObj"); if(ref!=0)ref->delete(); return pass; From d3ff720b77929bf745b99ddb761251deb05a2414 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Tue, 19 Jul 2016 19:59:36 +0530 Subject: [PATCH 78/91] Added cases for creating valid user and group --- tests/coal-pike/create.pike | 18 ++++++++++++++++-- tests/coal-pike/create_object.pike | 4 ++-- tests/coal-pike/test.pike | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/tests/coal-pike/create.pike b/tests/coal-pike/create.pike index 0529170..477c23f 100644 --- a/tests/coal-pike/create.pike +++ b/tests/coal-pike/create.pike @@ -1,6 +1,6 @@ #define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) -int testcase1(object me,object _Server) +int generalCreate(object me,object _Server) { object code = ((program)"create_object.pike")(); array(function) foo = values(code); @@ -16,7 +16,7 @@ int testcase1(object me,object _Server) return success; } -int testcase2(object me,object _Server) +int invalidClass(object me,object _Server) { int pass=0; write("Creating a class that does not exists\n"); @@ -25,4 +25,18 @@ int testcase2(object me,object _Server) return pass; } +int createUser(object me,object _Server) +{ + int pass = 0; + write("Creating a new user: "); + mixed result = catch{_Server->get_factory("User")->execute((["name":"testUser1","pw":"password","email":"user@steam.com"])); }; + if(result ==0)pass=1; + if(pass == 1) + { + write("passed\n"); + _Server->get_module("users")->get_user("testUser1")->delete(); + } + else write("failed\n"); + return pass; +} diff --git a/tests/coal-pike/create_object.pike b/tests/coal-pike/create_object.pike index 70f9c7c..6fa7bc2 100644 --- a/tests/coal-pike/create_object.pike +++ b/tests/coal-pike/create_object.pike @@ -6,8 +6,8 @@ int testcase(object me,object _Server,string type) object room = OBJ("/TestRoom"); mixed result =catch{ _Server->get_factory(type)->execute((["name":"TestObj"+type]))->move(room); }; if(result ==0)pass=1; - else if((type=="User"||type=="Group")&& result!=0)pass=1; - object ref = OBJ("/TestRoom/TestObj"); + else if((type=="User")&& result!=0)pass=1; + object ref = OBJ("/TestRoom/TestObj"+type); if(ref!=0)ref->delete(); return pass; diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index 12f3243..5b07c53 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -62,6 +62,6 @@ class Test{ int main(){ Test move = Test("move",4); move->run(); - Test create = Test("create",2); + Test create = Test("create",3); create->run(); } From 0973900da30044886771f4de8e4428c7a290268b Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Thu, 21 Jul 2016 16:52:33 +0530 Subject: [PATCH 79/91] Added the test case for calls to get_environment --- tests/coal-pike/getEnv.pike | 14 ++++++++++++++ tests/coal-pike/test.pike | 2 ++ 2 files changed, 16 insertions(+) create mode 100644 tests/coal-pike/getEnv.pike diff --git a/tests/coal-pike/getEnv.pike b/tests/coal-pike/getEnv.pike new file mode 100644 index 0000000..4714234 --- /dev/null +++ b/tests/coal-pike/getEnv.pike @@ -0,0 +1,14 @@ +#define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) + +int callingFunction(object me,object _Server) +{ + object parent = OBJ("/TestRoom"); + _Server->get_factory("Room")->execute((["name":"getEnv"]))->move(parent); + object obj = OBJ("/TestRoom/getEnv"); + int pass = 0; + write("Calling get_environment: "); + if(parent==obj->get_environment()) pass=1; + if(pass == 1) write("passed\n"); + else write("failed\n"); + return pass; +} diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index 5b07c53..84d68a0 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -64,4 +64,6 @@ int main(){ move->run(); Test create = Test("create",3); create->run(); + Test getEnv = Test("getEnv",1); + getEnv->run(); } From ec94508c42e0ee783bd154634dfa179fd5dec0a2 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Fri, 22 Jul 2016 19:00:45 +0530 Subject: [PATCH 80/91] Added general case argument to all test cases --- tests/coal-pike/create.pike | 6 +++--- tests/coal-pike/getEnv.pike | 2 +- tests/coal-pike/move.pike | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/coal-pike/create.pike b/tests/coal-pike/create.pike index 477c23f..8073646 100644 --- a/tests/coal-pike/create.pike +++ b/tests/coal-pike/create.pike @@ -1,6 +1,6 @@ #define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) -int generalCreate(object me,object _Server) +int generalCreate(object me,object _Server,object...args) { object code = ((program)"create_object.pike")(); array(function) foo = values(code); @@ -16,7 +16,7 @@ int generalCreate(object me,object _Server) return success; } -int invalidClass(object me,object _Server) +int invalidClass(object me,object _Server,object...args) { int pass=0; write("Creating a class that does not exists\n"); @@ -25,7 +25,7 @@ int invalidClass(object me,object _Server) return pass; } -int createUser(object me,object _Server) +int createUser(object me,object _Server,object...args) { int pass = 0; write("Creating a new user: "); diff --git a/tests/coal-pike/getEnv.pike b/tests/coal-pike/getEnv.pike index 4714234..f63e5b8 100644 --- a/tests/coal-pike/getEnv.pike +++ b/tests/coal-pike/getEnv.pike @@ -1,6 +1,6 @@ #define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) -int callingFunction(object me,object _Server) +int callingFunction(object me,object _Server,object...args) { object parent = OBJ("/TestRoom"); _Server->get_factory("Room")->execute((["name":"getEnv"]))->move(parent); diff --git a/tests/coal-pike/move.pike b/tests/coal-pike/move.pike index 773afad..fdff8c3 100644 --- a/tests/coal-pike/move.pike +++ b/tests/coal-pike/move.pike @@ -1,6 +1,6 @@ #define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) -int testcase1(object me,object _Server) +int testcase1(object me,object _Server,object...args) { int pass = 0; _Server->get_factory("Room")->execute((["name":"TestsubRoom"]))->move(OBJ("/TestRoom")); @@ -28,7 +28,7 @@ int testcase2(object me,object _Server) } */ -int testcase2(object me,object _Server) +int testcase2(object me,object _Server,object...args) { int pass = 1; object code = ((program)"move_nonexistential.pike")(); @@ -58,7 +58,7 @@ int testcase2(object me,object _Server) return pass; } -int testcase3(object me,object _Server) +int testcase3(object me,object _Server,object...args) { int pass = 0; mixed result = 0; @@ -73,7 +73,7 @@ int testcase3(object me,object _Server) return pass; } -int testcase4(object me,object _Server) +int testcase4(object me,object _Server,object...args) { int pass = 0; _Server->get_factory("Room")->execute((["name":"Testmove4"]))->move(OBJ("/TestRoom")); From 17f26e5273e76dbd8516729dd90d1d763015321e Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Sat, 23 Jul 2016 23:10:17 +0530 Subject: [PATCH 81/91] Added test case for user permission --- tests/coal-pike/test.pike | 10 ++++++++-- tests/coal-pike/userPermission.pike | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 tests/coal-pike/userPermission.pike diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index 84d68a0..ec7a985 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -12,6 +12,7 @@ class Test{ string name; object _Server; object me; + object conn; array(Testcase) cases; int failures; void create(string name,int totalCases){ @@ -24,6 +25,7 @@ class Test{ object obj = OBJ("/TestRoom"); if(obj!=0) obj->delete(); + write("===============================\n"); } void init(){ string host = "127.0.0.1"; @@ -34,13 +36,14 @@ class Test{ master()->add_program_path(server_path+"/conf/"); master()->add_program_path(server_path+"/spm/"); master()->add_program_path(server_path+"/server/net/coal/"); - object conn = ((program)"../spm/client_base.pike")(); + conn = ((program)"../spm/client_base.pike")(); conn->connect_server(host,port); conn->login("root","steam",1); _Server = conn->SteamObj(0); me = _Server->get_module("users")->lookup("root"); _Server->get_factory("Room")->execute((["name":"TestRoom"]))->move(OBJ("/")); me->move(OBJ("/TestRoom")); + write("===============================\n"); } int run(){ string n = name +".pike"; @@ -48,7 +51,7 @@ class Test{ array(function) foo = values(code); int success = 0; for(int i=0;i< sizeof(cases);i++){ - if(foo[i](me,_Server)==1){ + if(foo[i](me,_Server,conn)==1){ success+=1; } @@ -66,4 +69,7 @@ int main(){ create->run(); Test getEnv = Test("getEnv",1); getEnv->run(); + + Test perm = Test("userPermission",1); + perm->run(); } diff --git a/tests/coal-pike/userPermission.pike b/tests/coal-pike/userPermission.pike new file mode 100644 index 0000000..71a1a99 --- /dev/null +++ b/tests/coal-pike/userPermission.pike @@ -0,0 +1,26 @@ +#define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) + +int test(object me,object _Server,object...args) +{ + int pass = 0; + _Server->get_factory("User")->execute((["name":"testUser1","pw":"password1"])); + _Server->get_factory("User")->execute((["name":"testUser2","pw":"password2"])); + object user1 = _Server->get_module("users")->get_user("testUser1"); + object user2 = _Server->get_module("users")->get_user("testUser2"); + user1->activate_user(); + user2->activate_user(); + args[0]->login("testUser1","password1",1); + _Server->get_factory("Container")->execute((["name":"testCont"]))->move(OBJ("/home/testUser1")); + args[0]->login("testUser2","password2",1); + write("Trying to access container created by user1 as user2: "); + mixed result = catch{OBJ("/home/testUser1/testCont")->delete();}; + if(result!=0){ + pass=1; + write("passed\n"); + } + else write("failed\n"); + args[0]->login("root","steam",1); + user1->delete(); + user2->delete(); + return pass; +} From 0fb02ab9a2583255e37416ff55397900ec66654d Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Fri, 5 Aug 2016 22:38:23 +0530 Subject: [PATCH 82/91] Added the missing constant stash_help_doc --- tools/steam-shell.pike | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index 7f30149..290f7c2 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -794,4 +794,4 @@ string getpath() { return me->get_last_trail()->query_attribute("OBJ_PATH"); } - +constant stash_help_doc = #"This is a sTeam Advanced Shell. All the STASH commands work with normal pike commands. Tab completion is available for both STASH commands and pike commands.\n\n"; From a695f98cca6b45d9cdbdf044aec9df244d447d13 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Fri, 5 Aug 2016 23:23:47 +0530 Subject: [PATCH 83/91] Removed the use of compile_file --- tools/steam-shell.pike | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index 290f7c2..33dca3b 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -304,8 +304,8 @@ mapping init(array argv) master()->add_program_path(server_path+"/spm/"); master()->add_program_path(server_path+"/server/net/coal/"); -// conn = ((program)"client_base.pike")(); - conn = ((program)compile_file("../server/client_base.pike"))(); + conn = ((program)"../server/client_base.pike")(); +// conn = ((program)compile_file("../server/client_base.pike"))(); int start_time = time(); werror("Connecting to sTeam server...\n"); From 0a6131cd35a4476c7a2d08c6db1d8aad3adbf9ab Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Thu, 11 Aug 2016 23:17:56 +0530 Subject: [PATCH 84/91] Added documentation and minor code improvements --- tests/coal-pike/create.pike | 5 +++- tests/coal-pike/create_object.pike | 1 + tests/coal-pike/getEnv.pike | 1 + tests/coal-pike/move.pike | 32 +++++++++-------------- tests/coal-pike/move_nonexistential.pike | 1 + tests/coal-pike/test.pike | 33 +++++++++++++++++------- tests/coal-pike/userPermission.pike | 5 ++-- 7 files changed, 46 insertions(+), 32 deletions(-) diff --git a/tests/coal-pike/create.pike b/tests/coal-pike/create.pike index 8073646..ed85a3c 100644 --- a/tests/coal-pike/create.pike +++ b/tests/coal-pike/create.pike @@ -1,8 +1,9 @@ #define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) +// Generalized test case to create various types of objects int generalCreate(object me,object _Server,object...args) { - object code = ((program)"create_object.pike")(); + object code = ((program)"create_object.pike")(); //importing the file containing the generalized case array(function) foo = values(code); int success = 1; array(string) testClass = ({"Container","Document","Room","Exit","User","Group"}); @@ -16,6 +17,7 @@ int generalCreate(object me,object _Server,object...args) return success; } +//Creating object of a class that does not exists int invalidClass(object me,object _Server,object...args) { int pass=0; @@ -25,6 +27,7 @@ int invalidClass(object me,object _Server,object...args) return pass; } +//Creating user int createUser(object me,object _Server,object...args) { int pass = 0; diff --git a/tests/coal-pike/create_object.pike b/tests/coal-pike/create_object.pike index 6fa7bc2..0603d77 100644 --- a/tests/coal-pike/create_object.pike +++ b/tests/coal-pike/create_object.pike @@ -1,5 +1,6 @@ #define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) +//generalized test case for creating objects int testcase(object me,object _Server,string type) { int pass = 0; diff --git a/tests/coal-pike/getEnv.pike b/tests/coal-pike/getEnv.pike index f63e5b8..cf2deae 100644 --- a/tests/coal-pike/getEnv.pike +++ b/tests/coal-pike/getEnv.pike @@ -1,5 +1,6 @@ #define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) +// Tests the function getEnvironment int callingFunction(object me,object _Server,object...args) { object parent = OBJ("/TestRoom"); diff --git a/tests/coal-pike/move.pike b/tests/coal-pike/move.pike index fdff8c3..13ac18a 100644 --- a/tests/coal-pike/move.pike +++ b/tests/coal-pike/move.pike @@ -1,5 +1,6 @@ #define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) +//Move the current user to a room int testcase1(object me,object _Server,object...args) { int pass = 0; @@ -14,35 +15,24 @@ int testcase1(object me,object _Server,object...args) if(obj!=0)obj->delete(); return pass; } -/* -int testcase2(object me,object _Server) -{ - int pass = 0; - mixed result = catch{me->move(OBJ("nopath"));}; - write("Moving to a non existential location nopath.: "); - if(result !=0)pass=1; - if(pass==1)write("passed\n"); - else write("failed\n"); - me->move(OBJ("/TestRoom")); - return pass; -} -*/ +// Generalized test case to move objects to non exestential location +//Currently test Room and User. int testcase2(object me,object _Server,object...args) { int pass = 1; - object code = ((program)"move_nonexistential.pike")(); + object code = ((program)"move_nonexistential.pike")(); //imports the file containing the generalized test case array(function) foo = values(code); - _Server->get_factory("Room")->execute((["name":"move2Room"]))->move(OBJ("/TestRoom")); - _Server->get_factory("User")->execute((["name":"move2User","pw":"testpass","email":"abc@example.com"])); + _Server->get_factory("Room")->execute((["name":"move2Room"]))->move(OBJ("/TestRoom")); //Test Room to move + _Server->get_factory("User")->execute((["name":"move2User","pw":"testpass","email":"abc@example.com"])); //Test User to move _Server->get_module("users")->get_user("move2User")->activate_user(); array(object) testObjects = allocate(2); - do{ +// do{ testObjects[0]=OBJ("/TestRoom/move2Room"); - }while(testObjects[0]==0); - do{ +// }while(testObjects[0]==0); +// do{ testObjects[1]=_Server->get_module("users")->get_user("move2User"); - }while(testObjects[1]==0); +// }while(testObjects[1]==0); int success = 1; for(int i = 0;iget_class()+ " to a non existential path: "); @@ -58,6 +48,7 @@ int testcase2(object me,object _Server,object...args) return pass; } +//Moving user into a container int testcase3(object me,object _Server,object...args) { int pass = 0; @@ -73,6 +64,7 @@ int testcase3(object me,object _Server,object...args) return pass; } +//Moving a room inside a container int testcase4(object me,object _Server,object...args) { int pass = 0; diff --git a/tests/coal-pike/move_nonexistential.pike b/tests/coal-pike/move_nonexistential.pike index f02905a..02dfd7d 100644 --- a/tests/coal-pike/move_nonexistential.pike +++ b/tests/coal-pike/move_nonexistential.pike @@ -1,5 +1,6 @@ #define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) +// Generalized test case to move an object to a non exestential location int testcase(object me,object _Server,object x) { int pass = 0; diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index ec7a985..46be486 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -9,24 +9,35 @@ class Testcase{ } class Test{ - string name; + string name; //Name of the the test case set + + //variables used to establish connection and interact with the server object _Server; object me; object conn; - array(Testcase) cases; - int failures; - void create(string name,int totalCases){ + + + //array(Testcase) cases; + int cases; + int failures; + + //Initialize the test case name and the number of test cases and call the init method + void create(string name,int totalCases){ this.name=name; - cases = allocate(totalCases); + cases = totalCases; init(); } + + //Delete the objects created by the test suite and exit void destroy(){ me->move(OBJ("/home/steam")); object obj = OBJ("/TestRoom"); if(obj!=0) obj->delete(); - write("===============================\n"); +// write("===============================\n"); } + + //Establist a connection to the server and initialize the server variables void init(){ string host = "127.0.0.1"; int port = 1900; @@ -45,18 +56,22 @@ class Test{ me->move(OBJ("/TestRoom")); write("===============================\n"); } + + //Fetch the file containing the code for the test. + //Get all the test cases and execute them one by one + //record the status of the test int run(){ string n = name +".pike"; - object code = ((program)n)(); + object code = ((program)n)(); // Fetch the code for test cases as an object array(function) foo = values(code); int success = 0; - for(int i=0;i< sizeof(cases);i++){ + for(int i=0;i< cases;i++){ //loop through the cases and execute them one by one if(foo[i](me,_Server,conn)==1){ success+=1; } } - write("success: "+success+"\nfails: "+(sizeof(cases)-success)+"\n"); + write("success: "+success+"\nfails: "+(cases-success)+"\n"); } } diff --git a/tests/coal-pike/userPermission.pike b/tests/coal-pike/userPermission.pike index 71a1a99..a6cee87 100644 --- a/tests/coal-pike/userPermission.pike +++ b/tests/coal-pike/userPermission.pike @@ -1,5 +1,6 @@ #define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) +//Tests file permissions int test(object me,object _Server,object...args) { int pass = 0; @@ -10,10 +11,10 @@ int test(object me,object _Server,object...args) user1->activate_user(); user2->activate_user(); args[0]->login("testUser1","password1",1); - _Server->get_factory("Container")->execute((["name":"testCont"]))->move(OBJ("/home/testUser1")); + _Server->get_factory("Container")->execute((["name":"testCont"]))->move(OBJ("/home/testUser1")); //object being created by user1 and it belongs to user1. args[0]->login("testUser2","password2",1); write("Trying to access container created by user1 as user2: "); - mixed result = catch{OBJ("/home/testUser1/testCont")->delete();}; + mixed result = catch{OBJ("/home/testUser1/testCont")->delete();}; //User2 trys deleting the object belonging to user1 if(result!=0){ pass=1; write("passed\n"); From 43402ca7112cc6d00fda2754872bf7154a38cc9b Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Mon, 15 Aug 2016 18:39:27 +0530 Subject: [PATCH 85/91] Fixed test.pike and userPermission.pike to use all the objects as TestUser --- tests/coal-pike/test.pike | 31 +++++++++++++++++------------ tests/coal-pike/userPermission.pike | 15 ++++++++++---- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index 46be486..d444687 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -30,10 +30,9 @@ class Test{ //Delete the objects created by the test suite and exit void destroy(){ - me->move(OBJ("/home/steam")); - object obj = OBJ("/TestRoom"); - if(obj!=0) - obj->delete(); + conn->login("root","steam",1); + me->move(OBJ("/home/steam")); + _Server->get_module("users")->get_user("TestUser")->delete(); // write("===============================\n"); } @@ -51,9 +50,14 @@ class Test{ conn->connect_server(host,port); conn->login("root","steam",1); _Server = conn->SteamObj(0); - me = _Server->get_module("users")->lookup("root"); - _Server->get_factory("Room")->execute((["name":"TestRoom"]))->move(OBJ("/")); - me->move(OBJ("/TestRoom")); + object x = _Server->get_module("users")->get_user("TestUser"); + if(x) x->delete(); + _Server->get_factory("User")->execute((["name":"TestUser","pw":"password"])); + _Server->get_module("users")->get_user("TestUser")->activate_user(); + conn->login("TestUser","password",1); + me = _Server->get_module("users")->lookup("TestUser"); + _Server->get_factory("Room")->execute((["name":"TestRoom"]))->move(OBJ("/home/TestUser")); + me->move(OBJ("/home/TestUser")); write("===============================\n"); } @@ -78,13 +82,14 @@ class Test{ int main(){ - Test move = Test("move",4); - move->run(); - Test create = Test("create",3); - create->run(); - Test getEnv = Test("getEnv",1); - getEnv->run(); +// Test move = Test("move",4); +// move->run(); +// Test create = Test("create",3); +// create->run(); +// Test getEnv = Test("getEnv",1); +// getEnv->run(); Test perm = Test("userPermission",1); perm->run(); } +//test diff --git a/tests/coal-pike/userPermission.pike b/tests/coal-pike/userPermission.pike index a6cee87..8b2600f 100644 --- a/tests/coal-pike/userPermission.pike +++ b/tests/coal-pike/userPermission.pike @@ -4,10 +4,16 @@ int test(object me,object _Server,object...args) { int pass = 0; - _Server->get_factory("User")->execute((["name":"testUser1","pw":"password1"])); - _Server->get_factory("User")->execute((["name":"testUser2","pw":"password2"])); - object user1 = _Server->get_module("users")->get_user("testUser1"); + args[0]->login("root","steam",1); + object user1 = _Server->get_module("users")->get_user("testUser1"); object user2 = _Server->get_module("users")->get_user("testUser2"); + if(user1)user1->delete(); + if(user2)user2->delete(); + _Server->get_factory("User")->execute((["name":"testUser1","pw":"password1"])); + _Server->get_factory("User")->execute((["name":"testUser2","pw":"password2"])); + user1 = _Server->get_module("users")->get_user("testUser1"); + user2 = _Server->get_module("users")->get_user("testUser2"); + user1->activate_user(); user2->activate_user(); args[0]->login("testUser1","password1",1); @@ -23,5 +29,6 @@ int test(object me,object _Server,object...args) args[0]->login("root","steam",1); user1->delete(); user2->delete(); - return pass; + args[0]->login("TestUser","password",1); + return pass; } From ebc631919e098f7e4b3b376f16b09cf5446d11b0 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Mon, 15 Aug 2016 19:26:26 +0530 Subject: [PATCH 86/91] Fixed move.pike to use all objects as TestUser --- tests/coal-pike/move.pike | 36 ++++++++++++++++++++---------------- tests/coal-pike/test.pike | 6 +++--- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/tests/coal-pike/move.pike b/tests/coal-pike/move.pike index 13ac18a..8947760 100644 --- a/tests/coal-pike/move.pike +++ b/tests/coal-pike/move.pike @@ -4,14 +4,14 @@ int testcase1(object me,object _Server,object...args) { int pass = 0; - _Server->get_factory("Room")->execute((["name":"TestsubRoom"]))->move(OBJ("/TestRoom")); - object obj = OBJ("/TestRoom/TestsubRoom"); + _Server->get_factory("Room")->execute((["name":"TestsubRoom"]))->move(OBJ("/home/TestUser/TestRoom")); + object obj = OBJ("/home/TestUser/TestRoom/TestsubRoom"); mixed result = catch{me->move(obj);}; write("Moving user: "); if(result == 0)pass=1; if(pass==1)write("passed\n"); else write("failed\n"); - me->move(OBJ("/TestRoom")); + me->move(OBJ("/home/TestUser/TestRoom")); if(obj!=0)obj->delete(); return pass; } @@ -23,16 +23,18 @@ int testcase2(object me,object _Server,object...args) int pass = 1; object code = ((program)"move_nonexistential.pike")(); //imports the file containing the generalized test case array(function) foo = values(code); - _Server->get_factory("Room")->execute((["name":"move2Room"]))->move(OBJ("/TestRoom")); //Test Room to move + _Server->get_factory("Room")->execute((["name":"move2Room"]))->move(OBJ("/home/TestUser/TestRoom")); //Test Room to move + object test = _Server->get_module("users")->get_user("move2User"); + args[0]->login("root","steam",1); + if(test)test->delete(); + args[0]->login("TestUser","password",1); _Server->get_factory("User")->execute((["name":"move2User","pw":"testpass","email":"abc@example.com"])); //Test User to move + args[0]->login("root","steam",1); _Server->get_module("users")->get_user("move2User")->activate_user(); + args[0]->login("TestUser","password",1); array(object) testObjects = allocate(2); -// do{ - testObjects[0]=OBJ("/TestRoom/move2Room"); -// }while(testObjects[0]==0); -// do{ + testObjects[0]=OBJ("/home/TestUser/TestRoom/move2Room"); testObjects[1]=_Server->get_module("users")->get_user("move2User"); -// }while(testObjects[1]==0); int success = 1; for(int i = 0;iget_class()+ " to a non existential path: "); @@ -43,9 +45,11 @@ int testcase2(object me,object _Server,object...args) } if(success==0)pass=0; + args[0]->login("root","steam",1); if(testObjects[1]!=0) testObjects[1]->delete(); - return pass; + args[0]->login("TestUser","password",1); + return pass; } //Moving user into a container @@ -53,8 +57,8 @@ int testcase3(object me,object _Server,object...args) { int pass = 0; mixed result = 0; - int res =_Server->get_factory("Container")->execute((["name":"Testmove3"]))->move(OBJ("/TestRoom")); - object obj = OBJ("/TestRoom/Testmove3"); + int res =_Server->get_factory("Container")->execute((["name":"Testmove3"]))->move(OBJ("/home/TestUser/TestRoom")); + object obj = OBJ("/home/TestUser/TestRoom/Testmove3"); result = catch{me->move(obj);}; write("Moving user into a container: "); if(result != 0)pass=1; @@ -68,10 +72,10 @@ int testcase3(object me,object _Server,object...args) int testcase4(object me,object _Server,object...args) { int pass = 0; - _Server->get_factory("Room")->execute((["name":"Testmove4"]))->move(OBJ("/TestRoom")); - _Server->get_factory("Container")->execute((["name":"Testcontmove4"]))->move(OBJ("/TestRoom")); - object room = OBJ("/TestRoom/Testmove4"); - object container = OBJ("/TestRoom/Testcontmove4"); + _Server->get_factory("Room")->execute((["name":"Testmove4"]))->move(OBJ("/home/TestUser/TestRoom")); + _Server->get_factory("Container")->execute((["name":"Testcontmove4"]))->move(OBJ("/home/TestUser/TestRoom")); + object room = OBJ("/home/TestUser/TestRoom/Testmove4"); + object container = OBJ("/home/TestUser/TestRoom/Testcontmove4"); mixed result = catch{room->move(container);}; write("Moving room inside container: "); if(result!=0)pass=1; diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index d444687..60fe209 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -33,6 +33,7 @@ class Test{ conn->login("root","steam",1); me->move(OBJ("/home/steam")); _Server->get_module("users")->get_user("TestUser")->delete(); + conn->logout(); // write("===============================\n"); } @@ -82,8 +83,8 @@ class Test{ int main(){ -// Test move = Test("move",4); -// move->run(); + Test move = Test("move",4); + move->run(); // Test create = Test("create",3); // create->run(); // Test getEnv = Test("getEnv",1); @@ -92,4 +93,3 @@ int main(){ Test perm = Test("userPermission",1); perm->run(); } -//test From 8098563b7c3c7f228a317ab560e2b7e814e729bf Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Mon, 15 Aug 2016 19:38:27 +0530 Subject: [PATCH 87/91] Fixed getEnv.pike to access all objects as TestUser --- tests/coal-pike/getEnv.pike | 4 ++-- tests/coal-pike/test.pike | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/coal-pike/getEnv.pike b/tests/coal-pike/getEnv.pike index cf2deae..7bd9e9d 100644 --- a/tests/coal-pike/getEnv.pike +++ b/tests/coal-pike/getEnv.pike @@ -3,9 +3,9 @@ // Tests the function getEnvironment int callingFunction(object me,object _Server,object...args) { - object parent = OBJ("/TestRoom"); + object parent = OBJ("/home/TestUser/TestRoom"); _Server->get_factory("Room")->execute((["name":"getEnv"]))->move(parent); - object obj = OBJ("/TestRoom/getEnv"); + object obj = OBJ("/home/TestUser/TestRoom/getEnv"); int pass = 0; write("Calling get_environment: "); if(parent==obj->get_environment()) pass=1; diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index 60fe209..820aef1 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -87,8 +87,8 @@ int main(){ move->run(); // Test create = Test("create",3); // create->run(); -// Test getEnv = Test("getEnv",1); -// getEnv->run(); + Test getEnv = Test("getEnv",1); + getEnv->run(); Test perm = Test("userPermission",1); perm->run(); From 8e11c735171730ca2d16ede9a8a539d0716d8629 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Tue, 16 Aug 2016 00:58:30 +0530 Subject: [PATCH 88/91] Fixed create.pike and removed unnecessary delete statements --- tests/coal-pike/create.pike | 4 ++-- tests/coal-pike/create_object.pike | 4 +--- tests/coal-pike/move.pike | 5 ----- tests/coal-pike/test.pike | 4 ++-- 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/tests/coal-pike/create.pike b/tests/coal-pike/create.pike index ed85a3c..091f04e 100644 --- a/tests/coal-pike/create.pike +++ b/tests/coal-pike/create.pike @@ -26,7 +26,7 @@ int invalidClass(object me,object _Server,object...args) if(result == 0) pass =1; return pass; } - +/* //Creating user int createUser(object me,object _Server,object...args) { @@ -42,4 +42,4 @@ int createUser(object me,object _Server,object...args) else write("failed\n"); return pass; } - +*/ diff --git a/tests/coal-pike/create_object.pike b/tests/coal-pike/create_object.pike index 0603d77..abbcfdc 100644 --- a/tests/coal-pike/create_object.pike +++ b/tests/coal-pike/create_object.pike @@ -4,12 +4,10 @@ int testcase(object me,object _Server,string type) { int pass = 0; - object room = OBJ("/TestRoom"); + object room = OBJ("/home/TestUser/TestRoom"); mixed result =catch{ _Server->get_factory(type)->execute((["name":"TestObj"+type]))->move(room); }; if(result ==0)pass=1; else if((type=="User")&& result!=0)pass=1; - object ref = OBJ("/TestRoom/TestObj"+type); - if(ref!=0)ref->delete(); return pass; } diff --git a/tests/coal-pike/move.pike b/tests/coal-pike/move.pike index 8947760..90474a5 100644 --- a/tests/coal-pike/move.pike +++ b/tests/coal-pike/move.pike @@ -64,7 +64,6 @@ int testcase3(object me,object _Server,object...args) if(result != 0)pass=1; if(pass==1)write("passed\n"); else write("failed\n"); - if(obj!=0)obj->delete(); return pass; } @@ -81,9 +80,5 @@ int testcase4(object me,object _Server,object...args) if(result!=0)pass=1; if(pass==1)write("passed\n"); else write("failed\n"); - if(room!=0) - room->delete(); - if(container!=0) - container->delete(); return pass; } diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index 820aef1..8fc4b48 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -85,8 +85,8 @@ class Test{ int main(){ Test move = Test("move",4); move->run(); -// Test create = Test("create",3); -// create->run(); + Test create = Test("create",2); + create->run(); Test getEnv = Test("getEnv",1); getEnv->run(); From a7311ad049d514046d4a8cd391c76fe3d9d86ee0 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Tue, 16 Aug 2016 17:32:08 +0530 Subject: [PATCH 89/91] Added the createUser function to use to connection object logged in as root to create a new user --- tests/coal-pike/test.pike | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index 8fc4b48..0364ba8 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -15,7 +15,8 @@ class Test{ object _Server; object me; object conn; - + object _ServerRoot; + object connRoot; //array(Testcase) cases; int cases; @@ -49,12 +50,12 @@ class Test{ master()->add_program_path(server_path+"/server/net/coal/"); conn = ((program)"../spm/client_base.pike")(); conn->connect_server(host,port); - conn->login("root","steam",1); + connRoot = ((program)"../spm/client_base.pike")(); + connRoot->connect_server(host,port); + connRoot->login("root","steam",1); + _ServerRoot = connRoot->SteamObj(0); _Server = conn->SteamObj(0); - object x = _Server->get_module("users")->get_user("TestUser"); - if(x) x->delete(); - _Server->get_factory("User")->execute((["name":"TestUser","pw":"password"])); - _Server->get_module("users")->get_user("TestUser")->activate_user(); + createUser("TestUser","password"); conn->login("TestUser","password",1); me = _Server->get_module("users")->lookup("TestUser"); _Server->get_factory("Room")->execute((["name":"TestRoom"]))->move(OBJ("/home/TestUser")); @@ -71,13 +72,25 @@ class Test{ array(function) foo = values(code); int success = 0; for(int i=0;i< cases;i++){ //loop through the cases and execute them one by one - if(foo[i](me,_Server,conn)==1){ + if(foo[i](me,_Server,conn,createUser)==1){ success+=1; } } write("success: "+success+"\nfails: "+(cases-success)+"\n"); } + + int createUser(string name,string password){ + int result = 0; + object user = _ServerRoot->get_module("users")->get_user(name); + if(user)user->delete(); + mixed res = catch{ + _ServerRoot->get_factory("User")->execute((["name":name,"pw":password])); + _ServerRoot->get_module("users")->get_user(name)->activate_user(); + }; + if (res=0){write("Error creating user");return 0;} + else return 1; + } } From bc6674d2269f5e21a2dd779115f5d3d6bd5d9774 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Tue, 16 Aug 2016 17:45:56 +0530 Subject: [PATCH 90/91] Changed the test cases to use createUser function to create new users --- tests/coal-pike/move.pike | 13 +------------ tests/coal-pike/userPermission.pike | 20 +++++--------------- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/tests/coal-pike/move.pike b/tests/coal-pike/move.pike index 90474a5..2769fa4 100644 --- a/tests/coal-pike/move.pike +++ b/tests/coal-pike/move.pike @@ -24,14 +24,7 @@ int testcase2(object me,object _Server,object...args) object code = ((program)"move_nonexistential.pike")(); //imports the file containing the generalized test case array(function) foo = values(code); _Server->get_factory("Room")->execute((["name":"move2Room"]))->move(OBJ("/home/TestUser/TestRoom")); //Test Room to move - object test = _Server->get_module("users")->get_user("move2User"); - args[0]->login("root","steam",1); - if(test)test->delete(); - args[0]->login("TestUser","password",1); - _Server->get_factory("User")->execute((["name":"move2User","pw":"testpass","email":"abc@example.com"])); //Test User to move - args[0]->login("root","steam",1); - _Server->get_module("users")->get_user("move2User")->activate_user(); - args[0]->login("TestUser","password",1); + args[1]("move2User","testpass"); array(object) testObjects = allocate(2); testObjects[0]=OBJ("/home/TestUser/TestRoom/move2Room"); testObjects[1]=_Server->get_module("users")->get_user("move2User"); @@ -45,10 +38,6 @@ int testcase2(object me,object _Server,object...args) } if(success==0)pass=0; - args[0]->login("root","steam",1); - if(testObjects[1]!=0) - testObjects[1]->delete(); - args[0]->login("TestUser","password",1); return pass; } diff --git a/tests/coal-pike/userPermission.pike b/tests/coal-pike/userPermission.pike index 8b2600f..8f9e46a 100644 --- a/tests/coal-pike/userPermission.pike +++ b/tests/coal-pike/userPermission.pike @@ -4,18 +4,8 @@ int test(object me,object _Server,object...args) { int pass = 0; - args[0]->login("root","steam",1); - object user1 = _Server->get_module("users")->get_user("testUser1"); - object user2 = _Server->get_module("users")->get_user("testUser2"); - if(user1)user1->delete(); - if(user2)user2->delete(); - _Server->get_factory("User")->execute((["name":"testUser1","pw":"password1"])); - _Server->get_factory("User")->execute((["name":"testUser2","pw":"password2"])); - user1 = _Server->get_module("users")->get_user("testUser1"); - user2 = _Server->get_module("users")->get_user("testUser2"); - - user1->activate_user(); - user2->activate_user(); + args[1]("testUser1","password1"); + args[1]("testUser2","password2"); args[0]->login("testUser1","password1",1); _Server->get_factory("Container")->execute((["name":"testCont"]))->move(OBJ("/home/testUser1")); //object being created by user1 and it belongs to user1. args[0]->login("testUser2","password2",1); @@ -26,9 +16,9 @@ int test(object me,object _Server,object...args) write("passed\n"); } else write("failed\n"); - args[0]->login("root","steam",1); - user1->delete(); - user2->delete(); +// args[0]->login("root","steam",1); +// user1->delete(); +// user2->delete(); args[0]->login("TestUser","password",1); return pass; } From 470468a5e94a183bf18fe0b1883c0ccc636867b5 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Tue, 16 Aug 2016 18:16:40 +0530 Subject: [PATCH 91/91] Minor bug fixes --- tests/coal-pike/test.pike | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index 0364ba8..b7fa422 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -30,11 +30,11 @@ class Test{ } //Delete the objects created by the test suite and exit - void destroy(){ - conn->login("root","steam",1); - me->move(OBJ("/home/steam")); - _Server->get_module("users")->get_user("TestUser")->delete(); + void clear(){ + object user = _ServerRoot->get_module("users")->get_user("TestUser"); + if(user)user->delete(); conn->logout(); + connRoot->logout(); // write("===============================\n"); } @@ -98,11 +98,14 @@ class Test{ int main(){ Test move = Test("move",4); move->run(); + move->clear(); Test create = Test("create",2); create->run(); + create->clear(); Test getEnv = Test("getEnv",1); getEnv->run(); - + getEnv->clear(); Test perm = Test("userPermission",1); perm->run(); + perm->clear(); }