diff --git a/tools/VisTeam.pike b/tools/VisTeam.pike new file mode 100755 index 0000000..c581052 --- /dev/null +++ b/tools/VisTeam.pike @@ -0,0 +1,144 @@ +#!/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.")}); + //Variable from applauncher.pike to exit the script after execution. + exitcall=1; + 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 8a82d7e..5c5bd02 100644 --- a/tools/applauncher.pike +++ b/tools/applauncher.pike @@ -21,171 +21,228 @@ 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; +int exitcall=0; -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(exitcall==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="sudo*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..]); + } + 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="sudo*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..]); + } + + 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/edit.pike b/tools/edit.pike index 3e7512f..54cf7c3 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,10 @@ 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}); + //Variable from applauncher.pike to exit the script after execution. + exitcall=1; + return applaunch(filearr,demo); } void demo(){} diff --git a/tools/export-to-git.pike b/tools/export-to-git.pike index cc5bbb9..56fdc0e 100755 --- a/tools/export-to-git.pike +++ b/tools/export-to-git.pike @@ -191,10 +191,8 @@ int main(int argc, array(string) argv) ({"nopath",Getopt.NO_ARG,({"-N","--no-path"})}), )); options += mkmapping(opt[*][0], opt[*][1]); - options->src = argv[-2]; - options->dest = argv[-1]; _Server=conn->SteamObj(0); - export_to_git(OBJ(options->src), options->dest, ({ OBJ("/home") })); + export_to_git(argv, ({ OBJ("/home") })); } int count=0; @@ -246,24 +244,39 @@ string dir_check(string def, string dir) return ""; } -void git_create_branch(string to) +void git_create_branch(array(string) argv, string to) { string cur_time = replace(Calendar.now()->set_timezone("UTC")->format_nice(),([":":"-" , " ":"-"])); - Process.create_process(({ "git", "checkout", "--orphan", cur_time }), ([ "cwd": to ]))->wait(); + string branchname,branch_desc; + array(string) source = allocate(sizeof(argv)-2); + if(sizeof(argv)>3) + branchname = "MultipleSources-"+cur_time; + else + branchname = OBJ(argv[-2])->query_attribute("OBJ_PATH")[1..]+"-"+cur_time; + for(int i =1; i < sizeof(argv)-1; i++) + source[i-1] = argv[i]; + Process.create_process(({ "git", "checkout", "--orphan", branchname }), ([ "cwd": to ]))->wait(); Process.create_process(({ "git", "rm", "-rf", "."}),([ "cwd": to]))->wait(); + branchname="branch."+branchname+".description"; + branch_desc = "This branch contains the source folders: "+ String.implode_nicely(source); + Process.create_process(({"git", "config", branchname, branch_desc}),(["cwd": to]))->wait(); dir_check("",to); } -void export_to_git(object from, string to, void|array(object) exclude) +void export_to_git(array(string) argv, void|array(object) exclude) { string complete_path; + string to = argv[-1]; git_init(to); - git_create_branch(to); + git_create_branch(argv,to); + write("Commit message : sTeam export-to-git\n"); + git_commit("sTeam export-to-git", to, "root", "root@localhost", 0, 1); //empty commit + for(int i =1;isrc=argv[i]; + Object from = OBJ(options->src); if(!options->nopath) // only if paths have to be created complete_path = dir_check(to,options->src); git_object(from, to); - write("Commit message : sTeam export-to-git\n"); - git_commit("sTeam export-to-git", to, "root", "root@localhost", 0, 1); //empty commit sort(history->time, history); foreach(history;; mapping doc) { @@ -275,6 +288,7 @@ void export_to_git(object from, string to, void|array(object) exclude) if (author) author_username = author->get_user_name(); string author_email = sprintf("%s@%s", author_username, _Server->get_server_name()); - string hash = (string)git_commit(message, to, author->query_attribute("USER_FULLNAME"), author_email, doc->time); + string hash = (string)git_commit(message, to, author_username, author_email, doc->time); } + } } diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index 7470e7a..9a8a8e6 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. @@ -48,738 +53,747 @@ 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. +delete Delete an object. The user can delete the objects inside the current folder. User can delete objects like documents, containers and rooms. 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) in current Room.\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 "delete": + write("Delete an object. The user can delete the objects inside the current folder. User can delete objects like documents, containers and rooms.\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]](); - }; - - if(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 = ""; + 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, + "delete" : delete, + "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, + "delete" : delete, + "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 - toappend = "Here is a list of all "+what+" in the current room\n"; - foreach(display,string str) - { - a=a+(str+" "); - if(str=="Invalid command") - { - flag=1; - write(str+"\n"); +int list(string what) { + if (what == "" || what == 0) { + write("Wrong usage\n"); + return 0; } - } - if(flag==0) - write(toappend+a+"\n\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"); + } 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) { -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"); + write(toappend + "\n"); + write(sprintf("%#-80s", a)); + write("\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; - else - return ({"Invalid command"}); + 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); + 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"}); + } + -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 +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 { - 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"); - //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=""; - if(getpath()[-1]==47) //check last "/" - fullpath = getpath()+name; - else - 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 = ""; - if(getpath()[-1]==47) //check last "/" - fullpath = getpath()+gatename; - else - 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=""; - if(getpath()[-1]==47) //check last "/" - fullpath = getpath()+file_cont_name; - else - fullpath = getpath()+"/"+file_cont_name; - if(OBJ(fullpath)) +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 delete(string file_cont_name) { + + string fullpath = ""; + fullpath = getpath() + "/" + file_cont_name; + if(OBJ(fullpath)){ + OBJ(fullpath)->delete(); + write("Object deleted successfully.\n"); + } + else write("Object does not exist.\n") ; return 0; - return 0; } -int create_ob(string type,string name) -{ - string desc = readln->read("How would you describe it?\n"); - mapping data = ([]); - type = String.capitalize(type); - 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 ]); - } - 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") - myobj->move(OBJ(getpath())); - - 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)); + + return 0; + } -int peek(string container) -{ - string fullpath = ""; - if(getpath()[-1]==47) //check last "/" - fullpath = getpath()+container; - else - 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 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 filename) -{ - 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]); - return 0; +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; 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); + + 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"; diff --git a/tools/steam-shell.vim b/tools/steam-shell.vim new file mode 100644 index 0000000..d793677 --- /dev/null +++ b/tools/steam-shell.vim @@ -0,0 +1,21 @@ +command! Steam call Steamshell() +"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 +"Enter the Vi visual mode(v). Select the command using the Vi Visual mode. +"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. + +function! Steamshell() +"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. + let @0 = substitute(@0, '\n', " ", "g") +"Register % stores the value of current file from where the command is executed and adding -disp "opens it's log file. + execute "tabe %-disp | r! /usr/local/lib/steam/tools/steam-shell.pike". " ".@0 + silent !clear +endfunction +