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 "Gametype.h" |
---|
31 | |
---|
32 | #include "core/CoreIncludes.h" |
---|
33 | #include "core/ConsoleCommand.h" |
---|
34 | #include "objects/infos/PlayerInfo.h" |
---|
35 | |
---|
36 | namespace orxonox |
---|
37 | { |
---|
38 | SetConsoleCommand(Gametype, listPlayers, true); |
---|
39 | |
---|
40 | CreateUnloadableFactory(Gametype); |
---|
41 | |
---|
42 | Gametype::Gametype() |
---|
43 | { |
---|
44 | RegisterObject(Gametype); |
---|
45 | |
---|
46 | this->getConnectedClients(); |
---|
47 | |
---|
48 | COUT(0) << "created Gametype" << std::endl; |
---|
49 | } |
---|
50 | |
---|
51 | Gametype* Gametype::getCurrentGametype() |
---|
52 | { |
---|
53 | for (ObjectList<Gametype>::iterator it = ObjectList<Gametype>::begin(); it != ObjectList<Gametype>::end(); ++it) |
---|
54 | return (*it); |
---|
55 | |
---|
56 | return 0; |
---|
57 | } |
---|
58 | |
---|
59 | void Gametype::listPlayers() |
---|
60 | { |
---|
61 | Gametype* gametype = Gametype::getCurrentGametype(); |
---|
62 | |
---|
63 | if (gametype) |
---|
64 | { |
---|
65 | for (std::set<PlayerInfo*>::const_iterator it = gametype->players_.begin(); it != gametype->players_.end(); ++it) |
---|
66 | COUT(0) << "ID: " << (*it)->getClientID() << ", Name: " << (*it)->getName() << std::endl; |
---|
67 | } |
---|
68 | else |
---|
69 | { |
---|
70 | for (ObjectList<PlayerInfo>::iterator it = ObjectList<PlayerInfo>::begin(); it != ObjectList<PlayerInfo>::end(); ++it) |
---|
71 | COUT(0) << "ID: " << (*it)->getClientID() << ", Name: " << (*it)->getName() << std::endl; |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | void Gametype::clientConnected(unsigned int clientID) |
---|
76 | { |
---|
77 | COUT(0) << "client connected" << std::endl; |
---|
78 | |
---|
79 | // create new PlayerInfo instance |
---|
80 | PlayerInfo* player = new PlayerInfo(); |
---|
81 | player->setClientID(clientID); |
---|
82 | |
---|
83 | // add to clients-map |
---|
84 | assert(!this->clients_[clientID]); |
---|
85 | this->clients_[clientID] = player; |
---|
86 | } |
---|
87 | |
---|
88 | void Gametype::clientDisconnected(unsigned int clientID) |
---|
89 | { |
---|
90 | COUT(0) << "client disconnected" << std::endl; |
---|
91 | |
---|
92 | // remove from clients-map |
---|
93 | PlayerInfo* player = this->clients_[clientID]; |
---|
94 | this->clients_.erase(clientID); |
---|
95 | |
---|
96 | // delete PlayerInfo instance |
---|
97 | delete player; |
---|
98 | } |
---|
99 | |
---|
100 | void Gametype::addPlayer(PlayerInfo* player) |
---|
101 | { |
---|
102 | this->players_.insert(player); |
---|
103 | this->playerJoined(player); |
---|
104 | } |
---|
105 | |
---|
106 | void Gametype::removePlayer(PlayerInfo* player) |
---|
107 | { |
---|
108 | this->players_.erase(player); |
---|
109 | this->playerLeft(player); |
---|
110 | } |
---|
111 | |
---|
112 | void Gametype::playerJoined(PlayerInfo* player) |
---|
113 | { |
---|
114 | COUT(0) << "player " << player->getName() << " joined" << std::endl; |
---|
115 | } |
---|
116 | |
---|
117 | void Gametype::playerLeft(PlayerInfo* player) |
---|
118 | { |
---|
119 | COUT(0) << "player " << player->getName() << " left" << std::endl; |
---|
120 | } |
---|
121 | |
---|
122 | void Gametype::playerChangedName(PlayerInfo* player) |
---|
123 | { |
---|
124 | if (this->players_.find(player) != this->players_.end()) |
---|
125 | { |
---|
126 | if (player->getName() != player->getOldName()) |
---|
127 | { |
---|
128 | COUT(0) << "player " << player->getOldName() << " changed name to " << player->getName() << std::endl; |
---|
129 | } |
---|
130 | } |
---|
131 | } |
---|
132 | } |
---|