Core now detects and handles a changed maxplayers value (bug 2537 and bug 2758)

This commit is contained in:
Matt Woodrow
2008-09-26 19:08:49 +12:00
parent 4517031861
commit f4dba84ae5
8 changed files with 162 additions and 8 deletions
+8 -3
View File
@@ -93,7 +93,7 @@ unsigned int TopMenu::CalcMemUsage()
size += m_Config.strings.GetMemTable()->MemUsage();
size += (m_Config.cats.size() * sizeof(int));
size += (sizeof(topmenu_player_t) * m_max_clients);
size += (sizeof(topmenu_player_t) * (ABSOLUTE_PLAYER_LIMIT + 1));
size += (m_SortedCats.size() * sizeof(unsigned int));
size += (m_UnsortedCats.size() * sizeof(unsigned int));
size += (m_Categories.size() * (sizeof(topmenu_category_t *) + sizeof(topmenu_category_t)));
@@ -904,8 +904,8 @@ void TopMenu::SortCategoriesIfNeeded()
void TopMenu::CreatePlayers(int max_clients)
{
m_max_clients = max_clients;
m_clients = (topmenu_player_t *)malloc(sizeof(topmenu_player_t) * (max_clients + 1));
memset(m_clients, 0, sizeof(topmenu_player_t) * (max_clients + 1));
m_clients = (topmenu_player_t *)malloc(sizeof(topmenu_player_t) * (ABSOLUTE_PLAYER_LIMIT + 1));
memset(m_clients, 0, sizeof(topmenu_player_t) * (ABSOLUTE_PLAYER_LIMIT + 1));
}
void TopMenu::TearDownClient(topmenu_player_t *player)
@@ -1100,6 +1100,11 @@ unsigned int TopMenu::FindCategory(const char *name)
return obj->object_id;
}
void TopMenu::OnMaxPlayersChanged( int newvalue )
{
m_max_clients = newvalue;
}
int _SortObjectNamesDescending(const void *ptr1, const void *ptr2)
{
obj_by_name_t *obj1 = (obj_by_name_t *)ptr1;
+3
View File
@@ -42,6 +42,8 @@
using namespace SourceHook;
using namespace SourceMod;
#define ABSOLUTE_PLAYER_LIMIT 255 // not 256, so we can send the limit as a byte
struct config_category_t
{
int name;
@@ -162,6 +164,7 @@ private:
void OnClientDisconnected(int client);
void OnServerActivated(int max_clients);
bool OnIdentityRemoval(IdentityToken_t *owner);
void OnMaxPlayersChanged(int newvalue);
private:
config_root_t m_Config; /* Configuration from file */
topmenu_player_t *m_clients; /* Client array */
+10
View File
@@ -117,3 +117,13 @@ void TopMenuManager::DestroyTopMenu(ITopMenu *topmenu)
delete pMenu;
}
void TopMenuManager::OnMaxPlayersChanged( int newvalue )
{
List<TopMenu *>::iterator iter;
for (iter = m_TopMenus.begin(); iter != m_TopMenus.end(); iter++)
{
(*iter)->OnMaxPlayersChanged(newvalue);
}
}
+1
View File
@@ -58,6 +58,7 @@ public:
void OnClientDisconnected(int client);
void OnServerActivated(int max_clients);
void OnPluginUnloaded(IPlugin *plugin);
void OnMaxPlayersChanged(int newvalue);
private:
List<TopMenu *> m_TopMenus;
};