Explorar el Código

fix: classes are properly cleared when removed with #kill

data.c          Classes are properly cleared when removed with #kill.
dzp hace 2 años
padre
commit
b1dea4f757
Se han modificado 5 ficheros con 61 adiciones y 35 borrados
  1. 2 0
      mods/igr.mods
  2. 34 27
      src/class.c
  3. 12 2
      src/data.c
  4. 5 5
      src/mapper.c
  5. 8 1
      src/tintin.h

+ 2 - 0
mods/igr.mods

@@ -2,6 +2,8 @@ Jan 2024        2.02.42
 ------------------------------------------------------------------------------
 net.c           Fixed a bug causing #config color_patch to strip all colors.
 
+data.c          Classes are properly cleared when removed with #kill.
+
 Jan 2024        2.02.41
 ------------------------------------------------------------------------------
 

+ 34 - 27
src/class.c

@@ -161,6 +161,30 @@ int count_class(struct session *ses, struct listnode *group)
 	return cnt;
 }
 
+void clear_class(struct session *ses, struct listnode *group)
+{
+	size_t type, index;
+
+	check_all_events(ses, EVENT_FLAG_CLASS, 0, 1, "CLASS CLEAR", group->arg1);
+	check_all_events(ses, EVENT_FLAG_CLASS, 1, 1, "CLASS CLEAR %s", group->arg1, group->arg1);
+
+	for (type = 0 ; type < LIST_MAX ; type++)
+	{
+		if (!HAS_BIT(ses->list[type]->flags, LIST_FLAG_CLASS))
+		{
+			continue;
+		}
+
+		for (index = 0 ; index < ses->list[type]->used ; index++)
+		{
+			if (!strcmp(ses->list[type]->list[index]->group, group->arg1))
+			{
+				delete_index_list(ses->list[type], index--);
+			}
+		}
+	}
+}
+
 DO_CLASS(class_assign)
 {
 	if (node == NULL)
@@ -182,8 +206,6 @@ DO_CLASS(class_assign)
 
 DO_CLASS(class_clear)
 {
-	int type, index;
-
 	if (node == NULL)
 	{
 		show_message(ses, LIST_CLASS, "#CLASS {%s} DOES NOT EXIST.", arg1);
@@ -191,24 +213,7 @@ DO_CLASS(class_clear)
 		return ses;
 	}
 
-	check_all_events(ses, EVENT_FLAG_CLASS, 0, 1, "CLASS CLEAR", ses->group);
-	check_all_events(ses, EVENT_FLAG_CLASS, 1, 1, "CLASS CLEAR %s", ses->group, ses->group);
-
-	for (type = 0 ; type < LIST_MAX ; type++)
-	{
-		if (!HAS_BIT(ses->list[type]->flags, LIST_FLAG_CLASS))
-		{
-			continue;
-		}
-
-		for (index = 0 ; index < ses->list[type]->used ; index++)
-		{
-			if (!strcmp(ses->list[type]->list[index]->group, arg1))
-			{
-				delete_index_list(ses->list[type], index--);
-			}
-		}
-	}
+	clear_class(ses, node);
 
 	show_message(ses, LIST_CLASS, "#CLASS {%s} HAS BEEN CLEARED.", arg1);
 
@@ -304,8 +309,6 @@ DO_CLASS(class_list)
 
 DO_CLASS(class_kill)
 {
-	int group;
-
 	if (node == NULL)
 	{
 		show_message(ses, LIST_CLASS, "#CLASS {%s} DOES NOT EXIST.", arg1);
@@ -313,14 +316,18 @@ DO_CLASS(class_kill)
 		return ses;
 	}
 
-	class_clear(ses, node, arg1, arg2);
+//	Best to handle this in delete_node so it works with #kill
+
+//	class_clear(ses, node, arg1, arg2);
+
+	delete_node_list(ses, LIST_CLASS, node);
 
-	group = search_index_list(ses->list[LIST_CLASS], arg1, NULL);
+//	group = search_index_list(ses->list[LIST_CLASS], arg1, NULL);
 
-	delete_index_list(ses->list[LIST_CLASS], group);
+//	delete_index_list(ses->list[LIST_CLASS], group);
 
-	check_all_events(ses, EVENT_FLAG_CLASS, 0, 1, "CLASS DESTROYED", arg1);
-	check_all_events(ses, EVENT_FLAG_CLASS, 1, 1, "CLASS DESTROYED %s", arg1, arg1);
+//	check_all_events(ses, EVENT_FLAG_CLASS, 0, 1, "CLASS DESTROYED", arg1);
+//	check_all_events(ses, EVENT_FLAG_CLASS, 1, 1, "CLASS DESTROYED %s", arg1, arg1);
 
 	show_message(ses, LIST_CLASS, "#CLASS {%s} HAS BEEN KILLED.", arg1);
 

+ 12 - 2
src/data.c

@@ -369,7 +369,7 @@ void delete_node_list(struct session *ses, int type, struct listnode *node)
 	delete_index_list(ses->list[type], index);
 }
 
-void delete_node(int type, struct listnode *node)
+void delete_node(struct session *ses, int type, struct listnode *node)
 {
 	if (HAS_BIT(list_table[type].flags, LIST_FLAG_REGEX))
 	{
@@ -382,6 +382,8 @@ void delete_node(int type, struct listnode *node)
 	switch (type)
 	{
 		case LIST_CLASS:
+			clear_class(ses, node);
+
 			if (node->data)
 			{
 				free(node->data);
@@ -409,6 +411,14 @@ void delete_node(int type, struct listnode *node)
 	// dispose in memory update for one shot handling
 
 	insert_index_list(gtd->dispose_list, node, gtd->dispose_list->used);
+
+	switch (type)
+	{
+		case LIST_CLASS:
+			check_all_events(ses, EVENT_FLAG_CLASS, 0, 1, "CLASS DESTROYED", node->arg1);
+			check_all_events(ses, EVENT_FLAG_CLASS, 1, 1, "CLASS DESTROYED %s", node->arg1, node->arg1);
+			break;
+	}
 }
 
 void delete_index_list(struct listroot *root, int index)
@@ -417,7 +427,7 @@ void delete_index_list(struct listroot *root, int index)
 
 	remove_index_list(root, index);
 
-	delete_node(root->type, node);
+	delete_node(root->ses, root->type, node);
 }
 
 void dispose_node(struct listnode *node)

+ 5 - 5
src/mapper.c

@@ -286,11 +286,11 @@ int delete_map(struct session *ses)
 
 	// probably need to use a dummy node
 
-	delete_node(LIST_ACTION, ses->map->search->area);
-	delete_node(LIST_ACTION, ses->map->search->desc);
-	delete_node(LIST_ACTION, ses->map->search->name);
-	delete_node(LIST_ACTION, ses->map->search->note);
-	delete_node(LIST_ACTION, ses->map->search->terrain);
+	delete_node(ses, LIST_ACTION, ses->map->search->area);
+	delete_node(ses, LIST_ACTION, ses->map->search->desc);
+	delete_node(ses, LIST_ACTION, ses->map->search->name);
+	delete_node(ses, LIST_ACTION, ses->map->search->note);
+	delete_node(ses, LIST_ACTION, ses->map->search->terrain);
 
 	free(ses->map->search);
 

+ 8 - 1
src/tintin.h

@@ -1970,6 +1970,13 @@ extern DO_CHAT(chat_zap);
 
 #endif
 
+#ifndef __CLASS_H__
+#define __CLASS_H__
+
+extern void clear_class(struct session *ses, struct listnode *group);
+
+#endif
+
 #ifndef __COMMAND_H__
 #define __COMMAND_H__
 
@@ -2186,7 +2193,7 @@ extern void show_list(struct listroot *root, int level);
 extern void remove_node_list(struct session *ses, int type, struct listnode *node);
 extern void remove_index_list(struct listroot *root, int index);
 extern void dispose_node(struct listnode *node);
-extern void delete_node(int type, struct listnode *node);
+extern void delete_node(struct session *ses, int type, struct listnode *node);
 extern void delete_node_list(struct session *ses, int type, struct listnode *node);
 extern  int delete_node_with_wild(struct session *ses, int index, char *string);
 extern void delete_index_list(struct listroot *root, int index);