diff --git a/src/server/slave.c b/src/server/slave.c --- a/src/server/slave.c +++ b/src/server/slave.c @@ -32,12 +32,8 @@ #include - int main(int argc, char *argv[]) { - char curopt; - - int tmp; char *datadir; char *server; @@ -65,6 +61,7 @@ int main(int argc, char *argv[]) server = NULL; username = NULL; + char curopt; while(((char)-1) != (curopt = getopt(argc, argv, "u:h"))) { @@ -96,31 +93,11 @@ int main(int argc, char *argv[]) /* Notifies the user if there no username in .conf */ - if(username == NULL || strcmp(username, "!username") == 0 ) { - fprintf(stderr, "\nPlease ensure that your username is present in distrenslave.conf\n"); - return 0; - } - else - if( username != NULL || strcmp(username, "!username") != 0 ) - { - // Log in the user - if(login_user(username) == 1){ - fprintf(stderr, "You should now be logged into distren.\n"); - } - else - { - fprintf(stderr, "Login failed, please check your username. If you have not registered, please do so on the DistRen website.\n"); - return 0; - } - } - else - { - fprintf(stderr, "Please check your distrenslave.conf, it appears to be incorrectly formatted.\n"); - } + if(checkUsername(username)) + return 1; fprintf(stderr, "Connecting to server...\n"); - tmp = remoteio_open(&comm_slave, commonopts->remoteio, server); - if(tmp) + if(remoteio_open(&comm_slave, commonopts->remoteio, server)) { fprintf(stderr, "Error connecting to server; exiting\n"); return 1; @@ -141,8 +118,6 @@ int main(int argc, char *argv[]) char *pathtoXml; /* Full path to the job's xml file */ char *outputExt; /* Output Extension (e.g., JPG) */ - char *jobdatapath; /* Path to job data */ - int haveWork = 0; int quit = 0; @@ -157,22 +132,14 @@ int main(int argc, char *argv[]) /* If we got a frame */ if(haveWork) { - fprintf(stderr,"Got work from server...\n"); /* @TODO: Add remotio hooks */ // jobnum = remoteio_read(jobnum); /* Set jobnum from remoteio (we could use info from struct, but we need this info to download the xmlfile */ - //framenum = remoteio_read(jobnum); /* Set framenum from remoteio */ + // framenum = remoteio_read(jobnum); /* Set framenum from remoteio */ fprintf(stderr, "Preparing to render frame %d in job %d\n", framenum, jobnum); - // Variable Preparation - _distren_asprintf(&jobdatapath, "job%d", jobnum); - _distren_asprintf(&urltoTar, "http://data.distren.org/job%d/job%d.tar.gz", jobnum); // Prepares URL to download from - _distren_asprintf(&pathtoTar, "%s/stor/jobdata/job%d.tar.gz", datadir, jobnum); // Prepares destination to save to - _distren_asprintf(&pathtoJobfile, "%s/%s/job.blend", datadir, jobdatapath ); // Prepares the path to the jobfile - _distren_asprintf(&urltoOutput, "http://data.distren.org/tmp/", jobdatapath ); // Prepares the URL where output is posted - _distren_asprintf(&pathtoXml, "%s/job%d/job%d.xml", datadir, jobnum ); // Prepares the path to the job's XML file - free(jobdatapath); + prepareJobPaths(jobnum, datadir, &urltoTar, &pathtoTar, &pathtoJobfile, &urltoOutput, &pathtoXml); if(downloadTar(urltoTar, pathtoTar)) return 1; @@ -225,7 +192,7 @@ int main(int argc, char *argv[]) else fprintf(stderr,"Nothing to do. Idling...\n"); - // If the server says that every frame for the last jobnum is finished, OR if the data is getting old + // @TODO: If the server says that every frame for the last jobnum is finished, OR if the data is getting old if(1 == 0) { // Note: individual frames are already deleted after uploading, @@ -238,6 +205,6 @@ int main(int argc, char *argv[]) fprintf(stderr,"Closing connection to server...\n"); remoteio_close(comm_slave); - + fprintf(stderr,"Goodbye!\n"); return 0; }