Server Help

ASSS Custom Projects - ASSS dir (DOS) equivalent

Helicon - Sun Apr 13, 2003 7:45 pm
Post subject: ASSS dir (DOS) equivalent
Does ASSS (or subgame for that matter, im such a newbie) support a command akin to "dir" to list the contents of the directories? That would be really nifty... plus, could someone describe the putfile/getfile system for ASSS... with all those direcotries things are bound to get messy, right?!?!?!
Mine GO BOOM - Sun Apr 13, 2003 9:52 pm
Post subject:
Without doing any debugging on the code, you can use the following crappy code on a Win32 machine (hopefully). Just pop it into playercmd.c, and set the command access in the conf/ folder (probably conf/svs/groupdef.dir/sysop file).

Code: Show/Hide
local void Cdir(const char *params, Player *p, const Target *target)
{
   /* Just opens 'dir' command as a pipe and sends data back to user */
   FILE *f = _popen("dir", "r");
   char str[255];

   while (!foef(f))
   {
      if (fgets(str, sizeof(str), f) != NULL)
         chat->SendMessage(p, "%s", str);
   }
   _pclose(f);
}


As for linux, someone else can make a cross-platform command. A better method would be to use the same code that is used for the Arena Listing, and instead of looking for just folders, display all files.

BTW: I recommend NEVER passing the arguments of a command to a pipe/system call unless you REALLY know what your doing. Someone could easily make it change the command to something else that they may want, such as a delete command, etc.
Helicon - Sun Apr 13, 2003 10:24 pm
Post subject:
obviously, allowing custom access to any filesystem command is a very bad thing. I appreciate the code... nifty. It always sucked having junk on there you cant remember you named this or that... or that you never knew existed.

still, any explanation of how ASSS handles all those folders?
Mine GO BOOM - Mon Apr 14, 2003 11:12 pm
Post subject:
Handles all the folders? Having folders keeps it organized. That way maps can be in a maps/ folder, arenas in its own folder, etc.

If you mean how does ASSS handle file sendings? Right now, this is the code in admincmd.c (i believe will be in next public release):

Code: Show/Hide
local helptext_t getfile_help =
"Targets: none\n"
"Args: <filename>\n"
"Transfers the specified filefrom the server to the client.\n"
"The filename should include the full relative path from the server's\n"
"base directory.\n";

local void Cgetfile(const char *params, Player *p, const Target *target)
{
   const char *t1 = strrchr(params, '/');
   const char *t2 = strrchr(params, '\\');
   if (t2 > t1) t1 = t2;
   t1 = t1 ? t1 + 1 : params;

   if (params[0] == '/' || strstr(params, ".."))
      lm->LogP(L_MALICIOUS, "playercmd", p, "Attempted ?getfile with bad path: '%s'", params);
   else
      filetrans->SendFile(p, params, t1, 0);
}


So either you setup a nice ftp, or you start to memorize where all the files are. If you mean how does ASSS deal with browsing folders, its in the playercmd.c's Carena function. Directory listings can be found there (snipet of code follows for lazy people).

Code: Show/Hide
#ifndef WIN32
      char aconf[PATH_MAX];
      DIR *dir = opendir("arenas");
      if (dir)
      {
         struct dirent *de;
         while ((de = readdir(dir)))
         {
            /* every arena must have an arena.conf. this filters out
             * ., .., CVS, etc. */
            snprintf(aconf, PATH_MAX, "arenas/%s/arena.conf", de->d_name);
            if (
                  (pos-buf+strlen(de->d_name)) < 480 &&
                  access(aconf, R_OK) == 0 &&
                  (de->d_name[0] != '#' || seehid) &&
                  check_arena(buf, pos-buf, de->d_name)
               )
            {
               l = strlen(de->d_name) + 1;
               strncpy(pos, de->d_name, l);
               pos += l;
               *pos++ = 0;
               *pos++ = 0;
            }
         }
         closedir(dir);
      }
#else
      char aconf[PATH_MAX];
      struct _finddata_t fi;
      long FH = _findfirst("arenas/*", &fi);
      if (FH != -1)
      {
         do
         {
            if ((fi.attrib & _A_SUBDIR) &&
                strcmp(fi.name, "..") &&
                strcmp(fi.name, "."))
            {
               /* every arena must have an arena.conf */
               snprintf(aconf, PATH_MAX, "arenas/%s/arena.conf", fi.name);
               if (
                     (pos-buf+strlen(fi.name)) < 480 &&
                     access(aconf, R_OK) == 0 &&
                     (fi.name[0] != '#' || seehid) &&
                     check_arena(buf, pos-buf, fi.name)
                  )
               {
                  l = strlen(fi.name) + 1;
                  strncpy(pos, fi.name, l);
                  pos += l;
                  *pos++ = 0;
                  *pos++ = 0;
               }
            }
         } while (_findnext(FH,&fi) != -1);
         _findclose(FH);
      }
#endif

Helicon - Tue Apr 15, 2003 4:11 pm
Post subject:
Anyone think of builgin FTP in?
Mine GO BOOM - Tue Apr 15, 2003 4:24 pm
Post subject:
Why would you built FTP into a subspace server? Since the server will most likely be running on a linux machine (talking about actual hosting, not on a cable modem), you have WAY more options on how to protect the files, setup remote access, shell access, etc.
Dr Brain - Tue Apr 15, 2003 4:30 pm
Post subject:
Agreed, no need to reinvent the wheel. Especially if the reinvented one isn't as good.
Helicon - Tue Apr 15, 2003 5:07 pm
Post subject:
i didnt consider Linux
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group