Fixed incorrect class index validated when restored from cookies (forgot to substract by one). Specified filter settings on random spawn classes.

This commit is contained in:
richard 2009-10-10 17:37:30 +02:00
parent 7555b042b9
commit 92bffae62c
2 changed files with 41 additions and 16 deletions

View File

@ -66,11 +66,11 @@ ClassClientInit(client)
{ {
// Set default class indexes on the player. // Set default class indexes on the player.
ClassClientSetDefaultIndexes(client); ClassClientSetDefaultIndexes(client);
}
// Forward event to sub-modules // Forward event to sub-modules.
ClassOverlayClientInit(client); ClassOverlayClientInit(client);
} }
}
/** /**
* Called a client disconnects. * Called a client disconnects.

View File

@ -984,6 +984,28 @@ ClassClientSetDefaultIndexes(client = -1)
new bool:hashuman; new bool:hashuman;
new bool:hasadmin; new bool:hasadmin;
/*
* SETUP CLASS FILTER
*/
// Do not require any class flags to be set.
filter[ClassFilter_RequireFlags] = 0;
// Set filter to hide mother zombie classes.
filter[ClassFilter_DenyFlags] = ZR_CLASS_FLAG_MOTHER_ZOMBIE;
// Set filter to also hide admin-only classes if not admin.
filter[ClassFilter_DenyFlags] += !ZRIsClientAdmin(client) ? ZR_CLASS_FLAG_ADMIN_ONLY : 0;
// Specify client so it can check group permissions.
filter[ClassFilter_Client] = client;
/*
* GET CLASS INDEXES
*/
// Check if a client is specified. // Check if a client is specified.
if (clientvalid) if (clientvalid)
{ {
@ -1007,13 +1029,10 @@ ClassClientSetDefaultIndexes(client = -1)
// one so zero means no class set and will result in a invalid // one so zero means no class set and will result in a invalid
// class index when restored. // class index when restored.
// Setup filtering so group permission is checked on player first. // Check if class indexes are set and that the client pass the filter.
filter[ClassFilter_Client] = client; // If not, fall back to default class indexes. Otherwise substract
// index by one.
// Check if class indexes are set and that the client pass group if (zombieindex <= 0 || !ClassFilterMatch(zombieindex - 1, filter))
// permissions. If not, fall back to default class indexes. Otherwise
// substract index by one.
if (zombieindex <= 0 || !ClassFilterMatch(zombieindex, filter))
{ {
zombieindex = ClassGetDefaultSpawnClass(ZR_CLASS_TEAM_ZOMBIES, filter); zombieindex = ClassGetDefaultSpawnClass(ZR_CLASS_TEAM_ZOMBIES, filter);
} }
@ -1023,7 +1042,7 @@ ClassClientSetDefaultIndexes(client = -1)
haszombie = true; haszombie = true;
} }
if (humanindex <= 0 || !ClassFilterMatch(humanindex, filter)) if (humanindex <= 0 || !ClassFilterMatch(humanindex - 1, filter))
{ {
humanindex = ClassGetDefaultSpawnClass(ZR_CLASS_TEAM_HUMANS, filter); humanindex = ClassGetDefaultSpawnClass(ZR_CLASS_TEAM_HUMANS, filter);
} }
@ -1033,7 +1052,7 @@ ClassClientSetDefaultIndexes(client = -1)
hashuman = true; hashuman = true;
} }
if (adminindex <= 0 || !ClassFilterMatch(adminindex, filter)) if (adminindex <= 0 || !ClassFilterMatch(adminindex - 1, filter))
{ {
adminindex = ClassGetDefaultSpawnClass(ZR_CLASS_TEAM_ADMINS, filter); adminindex = ClassGetDefaultSpawnClass(ZR_CLASS_TEAM_ADMINS, filter);
} }
@ -1045,7 +1064,7 @@ ClassClientSetDefaultIndexes(client = -1)
} }
else else
{ {
// Setup filtering so classes with groups set are excluded. // Set filter to exclude classes that require groups.
filter[ClassFilter_Client] = -1; filter[ClassFilter_Client] = -1;
// Get default class indexes. // Get default class indexes.
@ -1054,7 +1073,10 @@ ClassClientSetDefaultIndexes(client = -1)
adminindex = ClassGetDefaultSpawnClass(ZR_CLASS_TEAM_ADMINS, filter); adminindex = ClassGetDefaultSpawnClass(ZR_CLASS_TEAM_ADMINS, filter);
} }
// Validate indexes.
/*
* VALIDATE INDEXES
*/
if (!ClassValidateIndex(zombieindex)) if (!ClassValidateIndex(zombieindex))
{ {
// Invalid class index. Fall back to default class in class config and // Invalid class index. Fall back to default class in class config and
@ -1065,7 +1087,6 @@ ClassClientSetDefaultIndexes(client = -1)
zombieindex = ClassGetDefaultClass(ZR_CLASS_TEAM_ZOMBIES, filter); zombieindex = ClassGetDefaultClass(ZR_CLASS_TEAM_ZOMBIES, filter);
} }
// Get human class index.
if (!ClassValidateIndex(humanindex)) if (!ClassValidateIndex(humanindex))
{ {
// Invalid class index. Fall back to default class in class config and // Invalid class index. Fall back to default class in class config and
@ -1076,7 +1097,6 @@ ClassClientSetDefaultIndexes(client = -1)
humanindex = ClassGetDefaultClass(ZR_CLASS_TEAM_HUMANS, filter); humanindex = ClassGetDefaultClass(ZR_CLASS_TEAM_HUMANS, filter);
} }
// Get admin class index.
if (!ClassValidateIndex(adminindex)) if (!ClassValidateIndex(adminindex))
{ {
// Invalid class index. Fall back to default class in class config if // Invalid class index. Fall back to default class in class config if
@ -1085,6 +1105,11 @@ ClassClientSetDefaultIndexes(client = -1)
adminindex = ClassGetDefaultClass(ZR_CLASS_TEAM_ADMINS, filter); adminindex = ClassGetDefaultClass(ZR_CLASS_TEAM_ADMINS, filter);
} }
/*
* MARK INDEXES AS SELECTED, UPDATE CACHE AND COOKIES
*/
// Check if a client is specified. // Check if a client is specified.
if (clientvalid) if (clientvalid)
{ {