ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/friend.C
(Generate patch)

Comparing deliantra/server/common/friend.C (file contents):
Revision 1.5 by root, Sun Sep 10 16:00:23 2006 UTC vs.
Revision 1.7 by root, Sun Oct 15 02:16:34 2006 UTC

1
2/*
3 * static char *rcsid_friend_c =
4 * "$Id: friend.C,v 1.5 2006/09/10 16:00:23 root Exp $";
5 */
6
7/* 1/*
8 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
9 3
10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
22 16
23 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 20
27 The authors can be reached via e-mail at crossfire-devel@real-time.com 21 The authors can be reached via e-mail at <crossfire@schmorp.de>
28*/ 22*/
29 23
30#include <global.h> 24#include <global.h>
31 25
32/* 26/*
54 } 48 }
55 49
56 ol = first_friendly_object; 50 ol = first_friendly_object;
57 first_friendly_object = get_objectlink (); 51 first_friendly_object = get_objectlink ();
58 first_friendly_object->ob = op; 52 first_friendly_object->ob = op;
59 first_friendly_object->id = op->count;
60 first_friendly_object->next = ol; 53 first_friendly_object->next = ol;
61} 54}
62 55
63/* 56/*
64 * Removes the specified object from the linked list of friendly objects. 57 * Removes the specified object from the linked list of friendly objects.
81 */ 74 */
82 if (first_friendly_object->ob == op) 75 if (first_friendly_object->ob == op)
83 { 76 {
84 obj = first_friendly_object; 77 obj = first_friendly_object;
85 first_friendly_object = obj->next; 78 first_friendly_object = obj->next;
86 free (obj); 79 delete obj;
87 } 80 }
88 else 81 else
89 { 82 {
90 objectlink *prev = first_friendly_object; 83 objectlink *prev = first_friendly_object;
91 84
93 { 86 {
94 if (obj->ob == op) 87 if (obj->ob == op)
95 break; 88 break;
96 prev = obj; 89 prev = obj;
97 } 90 }
91
98 if (obj) 92 if (obj)
99 { 93 {
100 /* This should not happen. But if it does, presumably the
101 * call to remove it is still valid.
102 */
103 if (obj->id != op->count)
104 {
105 LOG (llevError, "remove_friendly_object, tags do no match, %s, %d != %d\n",
106 op->name ? (const char *) op->name : "none", op->count, obj->id);
107 }
108 prev->next = obj->next; 94 prev->next = obj->next;
109 free (obj); 95 delete obj;
110 } 96 }
111 } 97 }
112} 98}
113 99
114/* 100/*
132clean_friendly_list (void) 118clean_friendly_list (void)
133{ 119{
134 objectlink *obj, *prev = NULL, *next; 120 objectlink *obj, *prev = NULL, *next;
135 int count = 0; 121 int count = 0;
136 122
137 for (obj = first_friendly_object; obj != NULL; obj = next) 123 for (obj = first_friendly_object; obj; obj = next)
138 { 124 {
139 next = obj->next; 125 next = obj->next;
140 if (QUERY_FLAG (obj->ob, FLAG_FREED) || !QUERY_FLAG (obj->ob, FLAG_FRIENDLY) || (obj->id != obj->ob->count)) 126 if (QUERY_FLAG (obj->ob, FLAG_FREED) || !QUERY_FLAG (obj->ob, FLAG_FRIENDLY))
141 { 127 {
142 if (prev) 128 if (prev)
143 {
144 prev->next = obj->next; 129 prev->next = obj->next;
145 }
146 else 130 else
147 {
148 first_friendly_object = obj->next; 131 first_friendly_object = obj->next;
149 } 132
150 count++; 133 count++;
151 free (obj); 134 delete obj;
152 } 135 }
153 /* If we removed the object, then prev is still valid. */
154 else 136 else
137 /* If we removed the object, then prev is still valid. */
155 prev = obj; 138 prev = obj;
156 } 139 }
140
157 if (count) 141 if (count)
158 LOG (llevDebug, "clean_friendly_list: Removed %d bogus links\n", count); 142 LOG (llevDebug, "clean_friendly_list: Removed %d bogus links\n", count);
159} 143}
160 144
161/* Checks if the given object is already in the friendly list or not 145/* Checks if the given object is already in the friendly list or not

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines