Login
User Name:

Password:



Register

Forgot your password?
void nanny_get_new_race -- comm.c
Mar 13, 2025 7:08 am
By Elwood
IPv6
Jan 25, 2025 10:45 pm
By Samson
mudstrlcpy and mudstrlcat
Jan 18, 2025 5:23 pm
By Samson
I3 and IMC
Jan 17, 2025 9:35 pm
By Samson
AFKMud 2.5.1
Jan 17, 2025 2:22 pm
By Samson
SWFotEFUSS 1.5.3
Author: Various
Submitted by: Samson
SWRFUSS 1.4.3
Author: Various
Submitted by: Samson
SmaugFUSS 1.9.8
Author: Various
Submitted by: Samson
AFKMud 2.5.2
Author: AFKMud Team
Submitted by: Samson
SmaugFUSS 1.9.7
Author: Various
Submitted by: Samson
Users Online
Anthropic, Bytespider, AhrefsBot, Amazonbot

Members: 0
Guests: 5
Stats
Files
Topics
Posts
Members
Newest Member
507
3,812
19,722
591
TracySpencer

» SmaugMuds » Bugfix Lists » LoP Bugfix List » Gfighting Issue
Forum Rules | Mark all | Recent Posts

Gfighting Issue
< Newer Topic :: Older Topic > Always something :)

Pages:<< prev 1 next >>
Post is unread #1 Jan 5, 2009 9:16 pm   
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,992
JoinedJul 26, 2005

 
This is just from a diff file so hope everyone can make sense of it easily enough :)
diff -ruNbB oldsrc/act_wiz.c src/act_wiz.c
--- oldsrc/act_wiz.c	2008-10-10 06:27:10.000000000 -0400
+++ src/act_wiz.c	2009-01-05 21:44:41.535000000 -0500
@@ -1668,7 +1668,7 @@
    CHAR_DATA *victim;
    DESCRIPTOR_DATA *d;
    char arg1[MIL], arg2[MIL], arg3[MIL];
-   bool found = false, pmobs = false, phating = false, phunting = false;
+   bool found = false, pmobs = false, phating = false, phunting = false, pfearing = false;
    int low = 1, high = MAX_LEVEL, count = 0;
 
    argument = one_argument( argument, arg1 );
@@ -1677,7 +1677,7 @@
    {
       if( arg1[0] == '\0' || arg2[0] == '\0' )
       {
-         send_to_pager( "\r\n&wUsage:  gfighting | gfighting <low> <high> | gfighting <low> <high> mobs\r\n", ch );
+         send_to_pager( "\r\n&wUsage:  gfighting | gfighting <low> <high> | gfighting <low> <high> mobs/hating/hunting/fearing\r\n", ch );
          return;
       }
       low = atoi( arg1 );
@@ -1695,9 +1696,11 @@
       phating = true;
    else if( !str_cmp( arg3, "hunting" ) )
       phunting = true;
+   else if( !str_cmp( arg3, "fearing" ) )
+      pfearing = true;
 
    pager_printf( ch, "\r\n&cGlobal %s conflict:\r\n", pmobs ? "mob" : "character" );
-   if( !pmobs && !phating && !phunting )
+   if( !pmobs && !phating && !phunting && !pfearing )
    {
       for( d = first_descriptor; d; d = d->next )
       {
@@ -1708,14 +1711,15 @@
             found = true;
             pager_printf( ch, "&w%-12.12s &C|%2d &wvs &C%2d| &w%-16.16s [%5d]  &c%-20.20s [%5d]\r\n",
                victim->name, victim->level, victim->fighting->who->level,
-               is_npc( victim->fighting->who ) ? victim->fighting->who->short_descr : victim->fighting->
-               who->name, is_npc( victim->fighting->who ) ? victim->fighting->who->pIndexData->vnum : 0,
+               ( is_npc( victim->fighting->who ) ? victim->fighting->who->short_descr 
+               : victim->fighting->who->name ),
+               ( is_npc( victim->fighting->who ) ? victim->fighting->who->pIndexData->vnum : 0 ),
                victim->in_room->area->name, !victim->in_room ? 0 : victim->in_room->vnum );
             count++;
          }
       }
    }
-   else if( !phating && !phunting )
+   else if( !phating && !phunting && !pfearing)
    {
       for( victim = first_char; victim; victim = victim->next )
       {
@@ -1733,6 +1737,25 @@
          }
       }
    }
+   else if( !phunting && !phating && pfearing )
+   {
+      for( victim = first_char; victim; victim = victim->next )
+      {
+         if( is_npc( victim )
+         && victim->in_room && can_see( ch, victim ) && victim->fearing && victim->level >= low && victim->level <= high )
+         {
+            found = true;
+            pager_printf( ch, "&w%-12.12s &C|%2d &wvs &C%2d| &w%-16.16s [%5d]  &c%-20.20s [%5d]\r\n",
+               victim->name, victim->level, victim->fearing->who ? victim->fearing->who->level : 0,
+               victim->fearing->who ? ( is_npc( victim->fearing->who ) ?
+               victim->fearing->who->short_descr : victim->fearing->who->name ) : victim->fearing->name,
+               victim->fearing->who ? ( is_npc( victim->fearing->who ) ?
+               victim->fearing->who->pIndexData->vnum : 0 ) : 0, victim->in_room->area->name,
+               !victim->in_room ? 0 : victim->in_room->vnum );
+            count++;
+         }
+      }
+   }
    else if( !phunting && phating )
    {
       for( victim = first_char; victim; victim = victim->next )
@@ -1742,9 +1765,11 @@
          {
             found = true;
             pager_printf( ch, "&w%-12.12s &C|%2d &wvs &C%2d| &w%-16.16s [%5d]  &c%-20.20s [%5d]\r\n",
-               victim->name, victim->level, victim->hating->who->level, is_npc( victim->hating->who ) ?
-               victim->hating->who->short_descr : victim->hating->who->name, is_npc( victim->hating->who ) ?
-               victim->hating->who->pIndexData->vnum : 0, victim->in_room->area->name,
+               victim->name, victim->level, victim->hating ? victim->hating->who->level : 0,
+               victim->hating->who ? ( is_npc( victim->hating->who ) ?
+               victim->hating->who->short_descr : victim->hating->who->name ) : victim->hating->name,
+               victim->hating->who ? ( is_npc( victim->hating->who ) ?
+               victim->hating->who->pIndexData->vnum : 0 ) : 0, victim->in_room->area->name,
                !victim->in_room ? 0 : victim->in_room->vnum );
             count++;
          }
@@ -1760,9 +1785,10 @@
          {
             found = true;
             pager_printf( ch, "&w%-12.12s &C|%2d &wvs &C%2d| &w%-16.16s [%5d]  &c%-20.20s [%5d]\r\n",
-               victim->name, victim->level, victim->hunting->who->level, is_npc( victim->hunting->who ) ?
-               victim->hunting->who->short_descr : victim->hunting->who->name,
-               is_npc( victim->hunting->who ) ? victim->hunting->who->pIndexData->vnum : 0,
+               victim->name, victim->level, victim->hunting->who ? victim->hunting->who->level : 0,
+               victim->hunting->who ? ( is_npc( victim->hunting->who ) ?
+               victim->hunting->who->short_descr : victim->hunting->who->name ) : victim->hunting->name,
+               victim->hunting->who ? ( is_npc( victim->hunting->who ) ? victim->hunting->who->pIndexData->vnum : 0 ) : 0,
                victim->in_room->area->name, !victim->in_room ? 0 : victim->in_room->vnum );
             count++;
          }
diff -ruNbB oldsrc/comm.c src/comm.c
--- oldsrc/comm.c	2008-10-10 06:27:10.000000000 -0400
+++ src/comm.c	2009-01-05 20:35:05.317600000 -0500
@@ -1732,7 +1739,7 @@
          ch = d->character;
          if( is_fighting( ch ) )
             ch->position = POS_STANDING;
-
+         fix_hhf( ch );
          log_printf_plus( LOG_COMM, get_trust( ch ), "%s (%s) has connected.", ch->name, d->host );
          show_title( d );
          break;
@@ -2345,6 +2352,7 @@
             ch->timer = 0;
             send_to_char( "Reconnecting.\r\n", ch );
             act( AT_ACTION, "$n has reconnected.", ch, NULL, NULL, TO_CANSEE );
+            fix_hhf( ch );
             if( ch->editor )
             {
                send_to_char( "Continue entering your text now (/? = help /s = save /c = clear /l = list)\r\n", ch );
@@ -2398,6 +2406,7 @@
          log_printf_plus( LOG_COMM, get_trust( ch ), "%s@%s reconnected, kicking off old link.",
              ch->pcdata->filename, d->host );
          send_to_char( "Reconnecting.\r\n", ch );
+         fix_hhf( ch );
          act( AT_ACTION, "$n has reconnected, kicking off old link.", ch, NULL, NULL, TO_CANSEE );
          d->connected = cstate;
          if( ch->editor )
diff -ruNbB oldsrc/db.c src/db.c
--- oldsrc/db.c	2008-10-10 06:27:10.000000000 -0400
+++ src/db.c	2009-01-05 21:22:39.700200000 -0500
@@ -2520,6 +2526,8 @@
       DISPOSE( host );
    }
 
+   stop_hhf( ch );
+
    STRFREE( ch->name );
    STRFREE( ch->short_descr );
    STRFREE( ch->long_descr );
diff -ruNbB oldsrc/fight.c src/fight.c
--- oldsrc/fight.c	2008-10-10 06:27:10.000000000 -0400
+++ src/fight.c	2009-01-05 21:33:18.083400000 -0500
@@ -29,6 +29,8 @@
 OBJ_DATA *ncorpse; /* Used to keep track of corpse */
 void handle_stat( CHAR_DATA *ch, short stat, bool silence, short chance );
 
+HHF_DATA *first_hhf, *last_hhf;
+
 void wear_obj( CHAR_DATA *ch, OBJ_DATA *obj, bool fReplace, short wear_bit );
 void update_clan_victory( CLAN_DATA *clan, CHAR_DATA *ch, CHAR_DATA *vict );
 void check_chareq( CHAR_DATA *ch );
@@ -250,16 +252,21 @@
 /* hunting, hating and fearing code - Thoric */
 bool is_hunting( CHAR_DATA *ch, CHAR_DATA *victim )
 {
-   if( !ch->hunting || ch->hunting->who != victim )
+   if( !ch->hunting )
       return false;
-
+   if( ch->hunting->who != NULL && ch->hunting->who == victim )
    return true;
+   if( !ch->hunting->who && ch->hunting->name && !str_cmp( ch->hunting->name, victim->name ) )
+      return true;
+
+   return false;
 }
 
 void stop_hunting( CHAR_DATA *ch )
 {
    if( !ch->hunting )
       return;
+   UNLINK( ch->hunting, first_hhf, last_hhf, next, prev );
    STRFREE( ch->hunting->name );
    DISPOSE( ch->hunting );
    ch->hunting = NULL;
@@ -269,22 +276,28 @@
 {
    stop_hunting( ch );
    CREATE( ch->hunting, HHF_DATA, 1 );
+   LINK( ch->hunting, first_hhf, last_hhf, next, prev );
    ch->hunting->name = QUICKLINK( victim->name );
    ch->hunting->who = victim;
 }
 
 bool is_hating( CHAR_DATA *ch, CHAR_DATA *victim )
 {
-   if( !ch->hating || ch->hating->who != victim )
+   if( !ch->hating )
       return false;
-
+   if( ch->hating->who != NULL && ch->hating->who == victim )
+      return true;
+   if( !ch->hating->who && ch->hating->name && !str_cmp( ch->hating->name, victim->name ) )
    return true;
+
+   return false;
 }
 
 void stop_hating( CHAR_DATA *ch )
 {
    if( !ch->hating )
       return;
+   UNLINK( ch->hating, first_hhf, last_hhf, next, prev );
    STRFREE( ch->hating->name );
    DISPOSE( ch->hating );
    ch->hating = NULL;
@@ -294,6 +307,7 @@
 {
    stop_hating( ch );
    CREATE( ch->hating, HHF_DATA, 1 );
+   LINK( ch->hating, first_hhf, last_hhf, next, prev );
    ch->hating->name = QUICKLINK( victim->name );
    ch->hating->who = victim;
 }
@@ -308,25 +322,30 @@
    {
       vch_next = vch->next_in_room;
 
-      if( vch->hunting && vch->hunting->who == ch )
+      if( vch->hunting && vch->hunting->who && vch->hunting->who == ch )
          stop_hunting( vch );
-      if( vch->hating && vch->hating->who == ch )
+      if( vch->hating && vch->hating->who && ch->hating->who == ch )
          stop_hating( vch );
    }
 }
 
 bool is_fearing( CHAR_DATA *ch, CHAR_DATA *victim )
 {
-   if( !ch->fearing || ch->fearing->who != victim )
+   if( !ch->fearing )
       return false;
-
+   if( ch->fearing->who != NULL && ch->fearing->who == victim )
+      return true;
+   if( !ch->fearing->who && ch->fearing->name && !str_cmp( ch->fearing->name, victim->name ) )
    return true;
+
+   return false;
 }
 
 void stop_fearing( CHAR_DATA *ch )
 {
    if( !ch->fearing )
       return;
+   UNLINK( ch->fearing, first_hhf, last_hhf, next, prev );
    STRFREE( ch->fearing->name );
    DISPOSE( ch->fearing );
    ch->fearing = NULL;
@@ -336,10 +355,64 @@
 {
    stop_fearing( ch );
    CREATE( ch->fearing, HHF_DATA, 1 );
+   LINK( ch->fearing, first_hhf, last_hhf, next, prev );
    ch->fearing->name = QUICKLINK( victim->name );
    ch->fearing->who = victim;
 }
 
+/* Ok so lets see if we can't stop them from logging out to avoid hate, hunt, fear */
+/* This will remove all but the name and fix it when they log back in */
+void stop_hhf( CHAR_DATA *ch )
+{
+   HHF_DATA *fhhf, *next_hhf;
+
+   if( !ch || ch->name == NULL || ch->name[0] == '\0' )
+      return;
+   for( fhhf = first_hhf; fhhf; fhhf = next_hhf )
+   {
+      next_hhf = fhhf->next;
+      if( !fhhf->who )
+         continue;
+      if( str_cmp( fhhf->name, ch->name ) )
+         continue;
+      fhhf->who = NULL;
+   }
+}
+
+/* Check to see if they are being hunted, hated, feared and if so set to the new char */
+void fix_hhf( CHAR_DATA *ch )
+{
+   HHF_DATA *fhhf, *next_hhf;
+
+   if( !ch || ch->name == NULL || ch->name[0] == '\0' )
+      return;
+   for( fhhf = first_hhf; fhhf; fhhf = next_hhf )
+   {
+      next_hhf = fhhf->next;
+      if( fhhf->who )
+         continue;
+      if( str_cmp( fhhf->name, ch->name ) )
+         continue;
+      fhhf->who = ch;
+   }
+}
+
+CMDF( do_showhhf )
+{
+   HHF_DATA *fhhf, *next_hhf;
+
+   if( !first_hhf )
+   {
+      send_to_char( "No current hunting, hating or fearing is going on.\r\n", ch );
+      return;
+   }
+   for( fhhf = first_hhf; fhhf; fhhf = next_hhf )
+   {
+      next_hhf = fhhf->next;
+      ch_printf( ch, "%s is in the list and %s a valid who pointer.\r\n", fhhf->name, fhhf->who ? "has" : "doesn't have" );
+   }
+}
+
 /*
  * Control the fights going on.
  * Called periodically by update_handler.
diff -ruNbB oldsrc/h/mud.h src/h/mud.h
--- oldsrc/h/mud.h	2008-10-10 06:27:10.000000000 -0400
+++ src/h/mud.h	2009-01-05 20:30:06.780400000 -0500
@@ -1035,10 +1035,14 @@
 
 struct hunt_hate_fear
 {
-   char *name;
+   HHF_DATA *next, *prev; /* Keep track of all the hunts hates and fears */
    CHAR_DATA *who;
+   char *name;
 };
 
+void stop_hhf( CHAR_DATA *ch );
+void fix_hhf( CHAR_DATA *ch );
+
 struct fighting_data
 {
    CHAR_DATA *who;

The problem is that someone could cause the game to crash if they worked it just right taking advantage of the fact that the pointer is never freed correctly. This is just one possible way of fixing it, and is the one I chose for now.

Pages:<< prev 1 next >>