aboutsummaryrefslogtreecommitdiff
path: root/src/environment.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/environment.cpp')
-rw-r--r--src/environment.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/environment.cpp b/src/environment.cpp
index c43525c37..906bab611 100644
--- a/src/environment.cpp
+++ b/src/environment.cpp
@@ -243,11 +243,44 @@ Player * Environment::getPlayer(u16 peer_id)
return NULL;
}
+Player * Environment::getPlayer(const char *name)
+{
+ for(core::list<Player*>::Iterator i = m_players.begin();
+ i != m_players.end(); i++)
+ {
+ Player *player = *i;
+ if(strcmp(player->getName(), name) == 0)
+ return player;
+ }
+ return NULL;
+}
+
core::list<Player*> Environment::getPlayers()
{
return m_players;
}
+core::list<Player*> Environment::getPlayers(bool ignore_disconnected)
+{
+ core::list<Player*> newlist;
+ for(core::list<Player*>::Iterator
+ i = m_players.begin();
+ i != m_players.end(); i++)
+ {
+ Player *player = *i;
+
+ if(ignore_disconnected)
+ {
+ // Ignore disconnected players
+ if(player->peer_id == 0)
+ continue;
+ }
+
+ newlist.push_back(player);
+ }
+ return newlist;
+}
+
void Environment::printPlayers(std::ostream &o)
{
o<<"Players in environment:"<<std::endl;