Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/PlayerManager.cc @ 2906

Last change on this file since 2906 was 2896, checked in by landauf, 16 years ago

Merged gui branch back to trunk.

I did 2 small changes in IngameManager.cc on line 777 and 888 (yes, really), because const_reverse_iterator strangely doesn't work on MinGW.

  • Property svn:eol-style set to native
File size: 3.3 KB
RevLine 
[2168]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "PlayerManager.h"
31
32#include "LevelManager.h"
[2896]33#include "core/GameMode.h"
[2168]34#include "core/CoreIncludes.h"
[2169]35#include "objects/Level.h"
[2168]36#include "objects/infos/HumanPlayer.h"
37
38namespace orxonox
39{
[2662]40    PlayerManager* PlayerManager::singletonRef_s = 0;
41
[2168]42    PlayerManager::PlayerManager()
43    {
44        RegisterRootObject(PlayerManager);
45
[2662]46        assert(singletonRef_s == 0);
47        singletonRef_s = this;
48
[2168]49        this->getConnectedClients();
50    }
51
52    PlayerManager::~PlayerManager()
53    {
[2662]54        assert(singletonRef_s);
55        singletonRef_s = 0;
[2168]56    }
57
58    void PlayerManager::clientConnected(unsigned int clientID)
59    {
[2896]60        if (GameMode::isMaster())
[2168]61        {
62            COUT(3) << "client connected" << std::endl;
63
64            // create new HumanPlayer instance
65            HumanPlayer* player = new HumanPlayer(0);
66            player->setClientID(clientID);
67
68            // add to clients-map
69            assert(!this->clients_[clientID]);
70            this->clients_[clientID] = player;
71
72            if (LevelManager::getInstancePtr() && LevelManager::getInstance().getActiveLevel())
73                LevelManager::getInstance().getActiveLevel()->playerEntered(player);
74        }
75    }
76
77    void PlayerManager::clientDisconnected(unsigned int clientID)
78    {
[2896]79        if (GameMode::isMaster())
[2168]80        {
81            COUT(3) << "client disconnected" << std::endl;
82
83            // remove from clients-map
84            PlayerInfo* player = this->clients_[clientID];
85            this->clients_.erase(clientID);
86
87            if (LevelManager::getInstancePtr() && LevelManager::getInstance().getActiveLevel())
88                LevelManager::getInstance().getActiveLevel()->playerLeft(player);
89
90            // delete PlayerInfo instance
91            if (player)
92                delete player;
93        }
94    }
95
96
97    PlayerInfo* PlayerManager::getClient(unsigned int clientID) const
98    {
[2896]99        if (GameMode::isMaster())
[2168]100        {
101            std::map<unsigned int, PlayerInfo*>::const_iterator it = this->clients_.find(clientID);
102            if (it != this->clients_.end())
103                return it->second;
104        }
105        else
106        {
107            for (ObjectList<PlayerInfo>::iterator it = ObjectList<PlayerInfo>::begin(); it != ObjectList<PlayerInfo>::end(); ++it)
108                if (it->getClientID() == clientID)
109                    return (*it);
110        }
111        return 0;
112    }
113}
Note: See TracBrowser for help on using the repository browser.