User Tools

Site Tools


server:running_the_server:compressed_map_files

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
server:running_the_server:compressed_map_files [2018/04/09 07:14] – Add pshops and privateshops to files to be omitted for being compressed karlserver:running_the_server:compressed_map_files [2025/04/18 13:08] (current) – external edit 127.0.0.1
Line 129: Line 129:
 Jump up to [[#Compression]] . Jump up to [[#Compression]] .
  
 +----
 +
 +===== Bugs and Patches ==
 +
 +The code has a flaw even until version 1.60.0 of the server trying to rename(filename, final), when their names \\
 +are identical. A bit further down, both file names get a different name by TEMP_EXT ".savefile" , so we need to \\
 +put that code there also in file //server/common/map.c// function //save_map()// :
 +<code diff>
 +      if (m->compressed && (m->unique || m->template || flag != SAVE_MODE_NORMAL)) {
 +          char buf[MAX_BUF];
 +          snprintf(buf, sizeof(buf), "%s > %s%s", uncomp[m->compressed][2], filename, TEMP_EXT);
 +          snprintf(final, sizeof(final), filename);
 ++         snprintf(filename, sizeof(filename), "%s%s", final, TEMP_EXT);
 +          fp = popen(buf, "w");
 +</code>
 +And probably use strcmp 2 times near and at the very end:
 +<code diff>
 +--- 1411,1461 ----
 +              } else {
 +                  fflush(fp2);
 +                  fclose (fp2);
 +                  unlink(final_unique); /* failure isn't too bad, maybe the file doesn't exist. */
 +
 +!                 if ( ( strcmp(buf, final_unique) != 0 ) && rename(buf, final_unique) == -1) {
 +!                     LOG(llevError, "new_save_map:Couldn't rename unique file %s to %s\n", buf, final_unique);
 +!                     if (m->compressed && (m->unique || m->template || flag != SAVE_MODE_NORMAL)) {
 +!                       pclose(fp);
 +!                     } else {
 +!                       fclose(fp);
 +!                     }
 +                      return SAVE_ERROR_URENAME;
 +                  }
 +                  chmod (final_unique, SAVE_MODE);
 +              }
 +
 +      unlink(final); /* failure isn't too bad, maybe the file doesn't exist. */
 +!     if (rename(filename, final) == -1) {
 +!         LOG(llevError, "Couldn't rename regular file %s to %s\n", filename, final);
 +          return SAVE_ERROR_RRENAME;
 +
 +      unlink(final); /* failure isn't too bad, maybe the file doesn't exist. */
 +!     if ( (strcmp(filename, final) != 0) && rename(filename, final) == -1) {
 +!         LOG(llevError, "save_map:Couldn't rename regular file %s to %s\n", filename, final);
 +          return SAVE_ERROR_RRENAME;
 +</code>
 +
 +==== 1.11.0 ==
 +
 +The code is faulty in version 1.11.0 of the server, not pclose'ing opened .savefiles. \\
 +The main errors are fixed in at least version 1.50.0, so it is a little bit disturbing, \\
 +why the compression code had been removed since 1.70.0 .
 +
 +Basically it is about backporting the code from v.1.50.0 .
 +
 +--- 
 +4 times pclose or fclose in **new_save_map()** ( common/map.c ) before early return from the function; \\
 +otherwise hundreds of shell commands compress will still be sleeping running and visible in a terminal through **ps** output:
 +<code diff>
 +--- 1359,1402 ----
 +      if ((flag == SAVE_MODE_NORMAL || flag == SAVE_MODE_OVERLAY) && !m->unique && !m->template) {
 +          char final_unique[MAX_BUF];
 +  
 +          snprintf(final_unique, sizeof(final_unique), "%s.v00", create_items_path (m->path));
 +          snprintf(buf, sizeof(buf), "%s%s", final_unique, TEMP_EXT);
 ++         LOG(llevDebug, "new_save_map:Saving unique map from %s to %s ...\n", buf, final_unique);
 +
 +          if ((fp2 = fopen (buf, "w")) == NULL) {
 +!             LOG(llevError, "new_save_map:Can't open unique items file %s\n", buf);
 +!             if (m->compressed && (m->unique || m->template || flag != SAVE_MODE_NORMAL)) {
 +!                 pclose(fp);
 +!             } else {
 +!                 fclose(fp);
 +!             }
 +              return SAVE_ERROR_UCREATION;
 +</code>
 +**Note**: m->template became  m->is_template in version 1.50.0 
 +---
 +
 +---
 +**res** needs to be set beforehand in **save_objects()** ( common/map.c ) , otherwise would return wronly :
 +<code diff>
 +  int save_objects (mapstruct *m, FILE *fp, FILE *fp2, int flag) {
 +!     int i, j = 0,unique=0, res=0;
 +      object *op,  *otmp;
 +
 +      /* first pass - save one-part objects */
 +      for(i = 0; i < MAP_WIDTH(m); i++)
 +      for (j = 0; j < MAP_HEIGHT(m); j++) {
 +</code>
server/running_the_server/compressed_map_files.1523276048.txt.gz · Last modified: (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki