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.6 by root, Thu Sep 14 22:33:58 2006 UTC vs.
Revision 1.8 by pippijn, Sat Jan 6 14:42:28 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
3 3
4 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 Copyright (C) 1992 Frank Tore Johansen
6 7
7 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
48 } 49 }
49 50
50 ol = first_friendly_object; 51 ol = first_friendly_object;
51 first_friendly_object = get_objectlink (); 52 first_friendly_object = get_objectlink ();
52 first_friendly_object->ob = op; 53 first_friendly_object->ob = op;
53 first_friendly_object->id = op->count;
54 first_friendly_object->next = ol; 54 first_friendly_object->next = ol;
55} 55}
56 56
57/* 57/*
58 * Removes the specified object from the linked list of friendly objects. 58 * Removes the specified object from the linked list of friendly objects.
75 */ 75 */
76 if (first_friendly_object->ob == op) 76 if (first_friendly_object->ob == op)
77 { 77 {
78 obj = first_friendly_object; 78 obj = first_friendly_object;
79 first_friendly_object = obj->next; 79 first_friendly_object = obj->next;
80 free (obj); 80 delete obj;
81 } 81 }
82 else 82 else
83 { 83 {
84 objectlink *prev = first_friendly_object; 84 objectlink *prev = first_friendly_object;
85 85
87 { 87 {
88 if (obj->ob == op) 88 if (obj->ob == op)
89 break; 89 break;
90 prev = obj; 90 prev = obj;
91 } 91 }
92
92 if (obj) 93 if (obj)
93 { 94 {
94 /* This should not happen. But if it does, presumably the
95 * call to remove it is still valid.
96 */
97 if (obj->id != op->count)
98 {
99 LOG (llevError, "remove_friendly_object, tags do no match, %s, %d != %d\n",
100 op->name ? (const char *) op->name : "none", op->count, obj->id);
101 }
102 prev->next = obj->next; 95 prev->next = obj->next;
103 free (obj); 96 delete obj;
104 } 97 }
105 } 98 }
106} 99}
107 100
108/* 101/*
126clean_friendly_list (void) 119clean_friendly_list (void)
127{ 120{
128 objectlink *obj, *prev = NULL, *next; 121 objectlink *obj, *prev = NULL, *next;
129 int count = 0; 122 int count = 0;
130 123
131 for (obj = first_friendly_object; obj != NULL; obj = next) 124 for (obj = first_friendly_object; obj; obj = next)
132 { 125 {
133 next = obj->next; 126 next = obj->next;
134 if (QUERY_FLAG (obj->ob, FLAG_FREED) || !QUERY_FLAG (obj->ob, FLAG_FRIENDLY) || (obj->id != obj->ob->count)) 127 if (QUERY_FLAG (obj->ob, FLAG_FREED) || !QUERY_FLAG (obj->ob, FLAG_FRIENDLY))
135 { 128 {
136 if (prev) 129 if (prev)
137 {
138 prev->next = obj->next; 130 prev->next = obj->next;
139 }
140 else 131 else
141 {
142 first_friendly_object = obj->next; 132 first_friendly_object = obj->next;
143 } 133
144 count++; 134 count++;
145 free (obj); 135 delete obj;
146 } 136 }
147 /* If we removed the object, then prev is still valid. */
148 else 137 else
138 /* If we removed the object, then prev is still valid. */
149 prev = obj; 139 prev = obj;
150 } 140 }
141
151 if (count) 142 if (count)
152 LOG (llevDebug, "clean_friendly_list: Removed %d bogus links\n", count); 143 LOG (llevDebug, "clean_friendly_list: Removed %d bogus links\n", count);
153} 144}
154 145
155/* Checks if the given object is already in the friendly list or not 146/* Checks if the given object is already in the friendly list or not

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines