Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/chat/src/orxonox/ChatHistory.cc @ 6690

Last change on this file since 6690 was 6690, checked in by smerkli, 15 years ago

Few changes before the questions, completing doxy stuff.

  • Property svn:eol-style set to native
File size: 4.3 KB
RevLine 
[6644]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 *      Sandro 'smerkli' Merkli
24 *   Co-authors:
25 *      ...
26 *
27 */
28
[6688]29#include "ChatHistory.h"
[6644]30
[6688]31#ifndef TEST
[6644]32namespace orxonox
33{
[6688]34#endif
[6690]35  /* QUESTION */
[6644]36  /* is this necessary? if yes uncomment please :P */
37  //CreateFactory(ChatHistory);
38
39  /* constructor */
[6688]40  #ifndef TEST
[6644]41  ChatHistory(BaseObject* creator) : BaseObject(creator) 
[6688]42  #else
43  ChatHistory::ChatHistory()
44  #endif
[6644]45  {
46    /* register the object */
[6688]47    #ifndef TEST
[6644]48    RegisterObject(ChatHistory);
[6688]49    #endif
[6644]50
[6688]51    this->hist_log_enabled = true;
52
[6644]53    /* Read setting for logfiles */
[6688]54    if( hist_log_enabled ) /* NOTE Make this a check for the logfile setting */
55    { this->chat_hist_openlog();
[6644]56
[6688]57      /* push starting line */
58      this->chat_hist_logline( "--- Logfile opened ---" );
59    }
60
[6644]61    /* Read setting for maximum number of lines and set limit */
62    this->hist_maxlines = 200; /* NOTE to be changed, 200 is just for testing */
63  }
64
65  /* destructor */
[6688]66  ChatHistory::~ChatHistory()
[6644]67  {
[6688]68    chat_hist_closelog();
69   
[6690]70    /* clear list */
71    this->hist_buffer.clear();
[6644]72  }
73
74  /* react to incoming chat */
[6688]75  void ChatHistory::incomingChat(const std::string& message, 
[6644]76    unsigned int senderID)
77  {
[6690]78    /* QUESTION */
[6644]79    /* sanity - check for valid senderID */
80
[6690]81    /* TODO make a correct name */
82    std::string name = "" + senderID; /* NOTE to be changed */
[6644]83
[6688]84    /* TODO */
[6690]85    /* QUESTION */
[6644]86    /* --> a) look up the actual name of the sender */
87    /* --> b) add sender name and string up with a separator
88     *    to make up the actual message
89     */
90
91    /* add the line to the history */
[6690]92    this->chat_hist_addline( name + ": " + message );
[6644]93
94    /* add the line to the log */
[6690]95    this->chat_hist_logline( name + ": " + message );
[6644]96  } 
97
[6649]98  /* Synchronize logfile onto the hard drive */ /* MARK MARK */
[6688]99  int ChatHistory::syncLog()
100  {
101    //if( this->hist_logfile )
102      //this->hist_logfile.sync();
103  }
[6644]104
105  /* add a line to this history */
[6688]106  int ChatHistory::chat_hist_addline( const std::string& toadd )
[6644]107  {
[6688]108    /* crop history at the end if it's too large */
109    while( this->hist_buffer.size() > this->hist_maxlines+1 )
110      this->hist_buffer.pop_front();
111
[6644]112    /* push to the front of the history */
[6688]113    this->hist_buffer.push_back( toadd );
[6644]114  }
115
116  /* log a line to a logfile */
117  int ChatHistory::chat_hist_logline( const std::string& toadd )
118  { 
119    /* output the line to the file if logging is enabled */
120    if( this->hist_log_enabled )
[6688]121      this->hist_logfile << toadd << std::endl;
[6644]122  }
123
124  /* open logfile */
125  int ChatHistory::chat_hist_openlog()
126  {
[6690]127    /* QUESTION */
[6644]128    /* TODO: find out the name of the file to log to via settings
129     *       and set the this->hist_logfile_path variable to it
130     */
131    this->hist_logfile.open( "/tmp/setsomepath.txt", 
[6688]132      std::fstream::out | std::fstream::app );
[6644]133
[6690]134    /* QUESTION */
[6644]135    /* TODO check whether this works (not sure how you'd like it?) */
136
137    /* if it worked */
138    return 0;
139  }
140
[6688]141  /* close logfile */
142  void ChatHistory::chat_hist_closelog()
143  {
144    if( this->hist_logfile )
145    { this->chat_hist_logline( "--- Logfile closed ---" );
146      this->hist_logfile.close();
147    }
148  }
149
150  /* output history for debugging */
151  void ChatHistory::debug_printhist()
152  {
[6690]153    /* create deque iterator */
[6688]154    std::deque<std::string>::iterator it;
155
[6690]156    /* output all the strings */
[6688]157    for( it = this->hist_buffer.begin(); it != this->hist_buffer.end();
158      ++it )
159      std::cout << *it << std::endl;
160
[6690]161    /* output size */
[6688]162    std::cout << "Size: " << hist_buffer.size() << std::endl;
163  }
164
165#ifndef TEST
[6644]166}
[6688]167#endif
Note: See TracBrowser for help on using the repository browser.