[Orxonox-commit 1927] r6644 - code/branches/chat/src/orxonox

smerkli at orxonox.net smerkli at orxonox.net
Mon Mar 29 16:41:20 CEST 2010


Author: smerkli
Date: 2010-03-29 16:41:19 +0200 (Mon, 29 Mar 2010)
New Revision: 6644

Added:
   code/branches/chat/src/orxonox/ChatHistory.cc
   code/branches/chat/src/orxonox/ChatHistory.h
Log:
Added initial chathistory cc file and header. Very basic, still, and incomplete.

Added: code/branches/chat/src/orxonox/ChatHistory.cc
===================================================================
--- code/branches/chat/src/orxonox/ChatHistory.cc	                        (rev 0)
+++ code/branches/chat/src/orxonox/ChatHistory.cc	2010-03-29 14:41:19 UTC (rev 6644)
@@ -0,0 +1,118 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Sandro 'smerkli' Merkli
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include <ChatHistory.h>
+
+namespace orxonox
+{
+  /* is this necessary? if yes uncomment please :P */
+  //CreateFactory(ChatHistory);
+
+  /* constructor */
+  ChatHistory(BaseObject* creator) : BaseObject(creator) 
+  {
+    /* register the object */
+    RegisterObject(ChatHistory);
+
+    /* Read setting for logfiles */
+    if( true ) /* NOTE Make this a check for the logfile setting */
+      this->chat_hist_openlog();
+
+    /* Read setting for maximum number of lines and set limit */
+    this->hist_maxlines = 200; /* NOTE to be changed, 200 is just for testing */
+
+    /* push starting line */
+    this->hist_buffer.push_front( "--- Logfile opened ---" )
+  }
+
+  /* destructor */
+  virtual ChatHistory::~ChatHistory()
+  {
+    /* check if loggin is enabled */
+      /* y -> synchronize the logfile */
+  }
+
+  /* react to incoming chat */
+  virtual void ChatHistory::incomingChat(const std::string& message, 
+    unsigned int senderID)
+  {
+    /* sanity - check for valid senderID */
+    /* sanity - check for valid string format */ 
+
+    /* format the message and senderID into a line */
+    std::string buf = "empty"; /* NOTE to be changed */
+
+    /* --> a) look up the actual name of the sender */
+    /* --> b) add sender name and string up with a separator
+     *    to make up the actual message
+     */
+
+    /* add the line to the history */
+    this->chat_hist_addline( buf );
+
+    /* add the line to the log */
+    this->chat_hist_logline( buf );
+  } 
+
+  /* Synchronize logfile onto the hard drive */
+  int ChatHistory::syncLog();
+
+  /* add a line to this history */
+  int ChatHistory::chat_hist_addline( const std::string& toadd );
+  {
+    /* push to the front of the history */
+    this->hist_buffer.push_front( toadd );
+
+    /* crop history at the end if it's too large */
+    this->hist_buffer.resize( this->hist_maxlines );
+  }
+
+  /* log a line to a logfile */
+  int ChatHistory::chat_hist_logline( const std::string& toadd )
+  { 
+    /* output the line to the file if logging is enabled */
+    if( this->hist_log_enabled )
+      this->hist_logfile << buf << std::endl;
+  }
+
+  /* open logfile */
+  int ChatHistory::chat_hist_openlog()
+  {
+    /* TODO: find out the name of the file to log to via settings 
+     *       and set the this->hist_logfile_path variable to it
+     */
+    this->hist_logfile.open( "/tmp/setsomepath.txt", 
+      fstream::out | fstream::app );
+
+    /* TODO check whether this works (not sure how you'd like it?) */
+
+    /* if it worked */
+    return 0;
+  }
+
+}

Added: code/branches/chat/src/orxonox/ChatHistory.h
===================================================================
--- code/branches/chat/src/orxonox/ChatHistory.h	                        (rev 0)
+++ code/branches/chat/src/orxonox/ChatHistory.h	2010-03-29 14:41:19 UTC (rev 6644)
@@ -0,0 +1,105 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Sandro 'smerkli' Merkli
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include <list>
+#include <core/BaseObject.h>
+
+#ifndef _ChatHistory_H__
+#define _ChatHistory_H__
+
+/* Class to implement chat history */
+namespace orxonox
+{
+  class _OrxonoxExport ChatHistory : public BaseObject, public ChatListener
+  {
+    public:
+      /* constructors, destructors */
+      ChatHistory(BaseObject* creator);
+      virtual ~ChatHistory();
+
+  
+    protected:
+      /** what to do with incoming chat 
+       * 
+       * \param message The incoming message 
+       * \param senderID Identification number of the sender
+       */
+      virtual void incomingChat(const std::string& message, 
+        unsigned int senderID);
+      
+      /** Synchronize logfile onto the hard drive 
+       *
+       * \return 0 for success, other for error
+       */
+      int syncLog();
+      
+    private:
+      /* FIELDS */
+      /** Vector to store the history in */
+      list<std::string> hist_buffer;
+
+      /** Maximum number of lines stored in this history */
+      unsigned int hist_maxlines;
+
+      /** is logging enabled? */
+      bool hist_log_enabled;
+
+      /** path of logfile on the file system */
+      std::string hist_logfile_path;
+
+      /** Output file stream for logfile */
+      ofstream hist_logfile;
+
+
+
+
+      /* METHODS */
+      /** Append line to chat history
+       *
+       * \param toadd The line to add to the history
+       * \return 0 for success, other for error TODO: Throw exception
+       */
+      int chat_hist_addline( const std::string& toadd );
+
+      /** Append line to logfile
+       *
+       * \param toadd The line to add to the logfile
+       * \return 0 for success, other for error TODO: Throw exception
+       */
+      int chat_hist_logline( const std::string& toadd );
+
+      /** open logfile to log to
+       *
+       * \return 0 for success,s other for error
+       */
+      int chat_hist_openlog();
+  }
+}
+
+
+#endif /* _ChatHistory_H__ */




More information about the Orxonox-commit mailing list