Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/notifications/Notification.cc @ 7463

Last change on this file since 7463 was 7463, checked in by dafrick, 14 years ago

Fixing "bug", that caused crash in dedicated mode.
Script object can now specify whether the code that is executed by it needs graphics to work.

  • Property svn:eol-style set to native
File size: 4.4 KB
Line 
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 thes
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 *      Damian 'Mozork' Frick
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file Notification.cc
31    @brief Implementation of the Notification class.
32*/
33
34#include "Notification.h"
35
36#include "core/CoreIncludes.h"
37#include "network/NetworkFunction.h"
38#include "network/Host.h"
39#include "NotificationManager.h"
40
41namespace orxonox
42{
43
44    CreateUnloadableFactory(Notification);
45
46    registerMemberNetworkFunction(Notification, send);
47
48    /**
49    @brief
50        Default constructor. Initializes the object.
51    @param creator
52        The object that created this Notification
53    */
54    Notification::Notification(BaseObject* creator) : BaseObject(creator), Synchronisable(creator)
55    {
56        RegisterObject(Notification);
57        this->initialize();
58        this->registerVariables();
59    }
60
61    /**
62    @brief
63        Constructor. Creates a Notification with the input message.
64    @param creator
65        The creator.
66    @param message
67        The message of the Notification.
68    */
69    Notification::Notification(BaseObject* creator, const std::string & message) : BaseObject(creator), Synchronisable(creator)
70    {
71        RegisterObject(Notification);
72        this->initialize();
73        this->message_ = message;
74        this->registerVariables();
75    }
76
77    /**
78    @brief
79        Destructor.
80    */
81    Notification::~Notification()
82    {
83
84    }
85
86    /**
87    @brief
88        Registers the object and sets some default values.
89    */
90    void Notification::initialize(void)
91    {
92        this->message_.clear();
93        this->sender_ = NotificationManager::NONE;
94        this->sent_ = false;
95    }
96
97    void Notification::registerVariables(void)
98    {
99        registerVariable(this->message_);
100        registerVariable(this->sender_);
101        registerVariable(this->sent_);
102    }
103
104    /**
105    @brief
106        Sends the Notification to the Notificationmanager, which then in turn distributes it to the different NotificationQueues.
107    @param clientId
108        The id of the client that this Notification is sent to.
109    @param sender
110        The sender the Notification was sent by. Used by the NotificationManager to distributes the notification to the correct NotificationQueues.
111    @return
112        Returns true if successful.
113    */
114    bool Notification::send(unsigned int clientId, const std::string & sender = NotificationManager::NONE)
115    {
116        COUT(0) << "MUP: " << Host::getPlayerID() << "|" << clientId << std::endl;
117        if(GameMode::isStandalone() || Host::getPlayerID() == clientId)
118        {
119            this->sendHelper(sender);
120        }
121        else if(GameMode::isServer())
122        {
123            callMemberNetworkFunction(Notification, send, this->getObjectID(), clientId, clientId, sender);
124        }
125
126        return true;
127    }
128
129    bool Notification::sendHelper(const std::string& sender)
130    {
131        if(this->isSent()) //TODO: Needed?
132            return false;
133
134        this->sender_ = sender;
135        bool successful = NotificationManager::getInstance().registerNotification(this);
136        if(!successful)
137            return false;
138        this->sent_ = true;
139
140        COUT(3) << "Notification \"" << this->getMessage() << "\" sent." << std::endl;
141
142        return true;
143    }
144
145    /**
146    @brief
147        Sets the message of the notification.
148    @param message
149        The message to be set.
150    @return
151        Returns true if successful.
152    */
153    bool Notification::setMessage(const std::string & message)
154    {
155        if(this->isSent()) //!< The message cannot be changed if the message has already been sent.
156            return false;
157        this->message_ = message;
158        return true;
159    }
160
161}
Note: See TracBrowser for help on using the repository browser.