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 "GametypeInfo.h" |
---|
30 | |
---|
31 | #include "core/CoreIncludes.h" |
---|
32 | #include "core/GameMode.h" |
---|
33 | #include "network/NetworkFunction.h" |
---|
34 | #include "network/Host.h" |
---|
35 | #include "interfaces/GametypeMessageListener.h" |
---|
36 | |
---|
37 | namespace orxonox |
---|
38 | { |
---|
39 | CreateUnloadableFactory(GametypeInfo); |
---|
40 | |
---|
41 | registerMemberNetworkFunction(GametypeInfo, dispatchAnnounceMessage); |
---|
42 | registerMemberNetworkFunction(GametypeInfo, dispatchKillMessage); |
---|
43 | registerMemberNetworkFunction(GametypeInfo, dispatchDeathMessage); |
---|
44 | |
---|
45 | GametypeInfo::GametypeInfo(BaseObject* creator) : Info(creator) |
---|
46 | { |
---|
47 | RegisterObject(GametypeInfo); |
---|
48 | |
---|
49 | this->bStarted_ = false; |
---|
50 | this->bEnded_ = false; |
---|
51 | this->startCountdown_ = 0; |
---|
52 | this->bStartCountdownRunning_ = false; |
---|
53 | |
---|
54 | this->registerVariables(); |
---|
55 | } |
---|
56 | |
---|
57 | GametypeInfo::~GametypeInfo() |
---|
58 | { |
---|
59 | } |
---|
60 | |
---|
61 | void GametypeInfo::registerVariables() |
---|
62 | { |
---|
63 | registerVariable(this->bStarted_, VariableDirection::ToClient); |
---|
64 | registerVariable(this->bEnded_, VariableDirection::ToClient); |
---|
65 | registerVariable(this->startCountdown_, VariableDirection::ToClient); |
---|
66 | registerVariable(this->bStartCountdownRunning_, VariableDirection::ToClient); |
---|
67 | registerVariable(this->hudtemplate_, VariableDirection::ToClient); |
---|
68 | } |
---|
69 | |
---|
70 | void GametypeInfo::sendAnnounceMessage(const std::string& message) |
---|
71 | { |
---|
72 | if (GameMode::isMaster()) |
---|
73 | { |
---|
74 | callMemberNetworkFunction(GametypeInfo, dispatchAnnounceMessage, this->getObjectID(), CLIENTID_UNKNOWN, message); |
---|
75 | this->dispatchAnnounceMessage(message); |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | void GametypeInfo::sendAnnounceMessage(const std::string& message, unsigned int clientID) |
---|
80 | { |
---|
81 | if (GameMode::isMaster()) |
---|
82 | { |
---|
83 | if (clientID == CLIENTID_SERVER) |
---|
84 | this->dispatchAnnounceMessage(message); |
---|
85 | else |
---|
86 | callMemberNetworkFunction(GametypeInfo, dispatchAnnounceMessage, this->getObjectID(), clientID, message); |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | void GametypeInfo::sendKillMessage(const std::string& message, unsigned int clientID) |
---|
91 | { |
---|
92 | if (GameMode::isMaster()) |
---|
93 | { |
---|
94 | if (clientID == CLIENTID_SERVER) |
---|
95 | this->dispatchKillMessage(message); |
---|
96 | else |
---|
97 | callMemberNetworkFunction(GametypeInfo, dispatchKillMessage, this->getObjectID(), clientID, message); |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | void GametypeInfo::sendDeathMessage(const std::string& message, unsigned int clientID) |
---|
102 | { |
---|
103 | if (GameMode::isMaster()) |
---|
104 | { |
---|
105 | if (clientID == CLIENTID_SERVER) |
---|
106 | this->dispatchDeathMessage(message); |
---|
107 | else |
---|
108 | callMemberNetworkFunction(GametypeInfo, dispatchDeathMessage, this->getObjectID(), clientID, message); |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | void GametypeInfo::dispatchAnnounceMessage(const std::string& message) |
---|
113 | { |
---|
114 | for (ObjectList<GametypeMessageListener>::iterator it = ObjectList<GametypeMessageListener>::begin(); it != ObjectList<GametypeMessageListener>::end(); ++it) |
---|
115 | it->announcemessage(this, message); |
---|
116 | } |
---|
117 | |
---|
118 | void GametypeInfo::dispatchKillMessage(const std::string& message) |
---|
119 | { |
---|
120 | for (ObjectList<GametypeMessageListener>::iterator it = ObjectList<GametypeMessageListener>::begin(); it != ObjectList<GametypeMessageListener>::end(); ++it) |
---|
121 | it->killmessage(this, message); |
---|
122 | } |
---|
123 | |
---|
124 | void GametypeInfo::dispatchDeathMessage(const std::string& message) |
---|
125 | { |
---|
126 | for (ObjectList<GametypeMessageListener>::iterator it = ObjectList<GametypeMessageListener>::begin(); it != ObjectList<GametypeMessageListener>::end(); ++it) |
---|
127 | it->deathmessage(this, message); |
---|
128 | } |
---|
129 | } |
---|