Sfoglia il codice sorgente

Cleaned up do_reload_instance. Fixes #1359.
* Added mode-specific handling of instance reload.
* Resolved potential crash when not on IM_PARTY mode.
Thanks to @iubantot.

Jittapan Pluemsumran 9 anni fa
parent
commit
e219dd9510
1 ha cambiato i file con 27 aggiunte e 8 eliminazioni
  1. 27 8
      src/map/instance.c

+ 27 - 8
src/map/instance.c

@@ -952,15 +952,34 @@ void do_reload_instance(void)
 		if(sd && map[sd->bl.m].instance_id) {
 			struct party_data *p = NULL;
 			struct guild *g = NULL;
-
-			if (instance_data[map[sd->bl.m].instance_id].mode == IM_PARTY && (!(p = party_search(sd->status.party_id)) || p->instance_id != map[sd->bl.m].instance_id)) // Someone not in party is on instance map
-				continue;
-			if (instance_data[map[sd->bl.m].instance_id].mode == IM_GUILD && (!(g = guild_search(sd->status.guild_id)) || g->instance_id != map[sd->bl.m].instance_id)) // Someone not in guild is on instance map
-				continue;
-			im = &instance_data[p->instance_id];
-			if((db = instance_searchtype_db(im->type)) != NULL && !instance_enter(sd, i, StringBuf_Value(db->name))) { // All good
+			unsigned short instance_id;
+
+			im = &instance_data[map[sd->bl.m].instance_id];
+			switch (im->mode) {
+				case IM_NONE:
+					continue;
+				case IM_CHAR:
+					if (sd->instance_id != map[sd->bl.m].instance_id) // Someone who is not instance owner is on instance map
+						continue;
+					instance_id = sd->instance_id;
+					break;
+				case IM_PARTY:
+					if ((!(p = party_search(sd->status.party_id)) || p->instance_id != map[sd->bl.m].instance_id)) // Someone not in party is on instance map
+						continue;
+					instance_id = p->instance_id;
+					break;
+				case IM_GUILD:
+					if (!(g = guild_search(sd->status.guild_id)) || g->instance_id != map[sd->bl.m].instance_id) // Someone not in guild is on instance map
+						continue;
+					instance_id = g->instance_id;
+					break;
+				default:
+					ShowError("do_reload_instance: Unexpected instance mode for instance %s(id=%u, mode=%u).\n", StringBuf_Value(db->name), map[sd->bl.m].instance_id, (unsigned short)im->mode);
+					continue;
+			}
+			if((db = instance_searchtype_db(im->type)) != NULL && !instance_enter(sd, instance_id, StringBuf_Value(db->name))) { // All good
 				clif_displaymessage(sd->fd, msg_txt(sd,515)); // Instance has been reloaded
-				instance_reqinfo(sd,p->instance_id);
+				instance_reqinfo(sd,instance_id);
 			} else // Something went wrong
 				ShowError("do_reload_instance: Error setting character at instance start: character_id=%d instance=%s.\n",sd->status.char_id,StringBuf_Value(db->name));
 		}