[Orxonox-commit 1976] r6693 - code/branches/chat/src/orxonox
smerkli at orxonox.net
smerkli at orxonox.net
Mon Apr 12 16:06:46 CEST 2010
Author: smerkli
Date: 2010-04-12 16:06:46 +0200 (Mon, 12 Apr 2010)
New Revision: 6693
Modified:
code/branches/chat/src/orxonox/ChatHistory.cc
code/branches/chat/src/orxonox/ChatHistory.h
Log:
questions resolved, ready for in-game testing.
Modified: code/branches/chat/src/orxonox/ChatHistory.cc
===================================================================
--- code/branches/chat/src/orxonox/ChatHistory.cc 2010-04-12 14:00:30 UTC (rev 6692)
+++ code/branches/chat/src/orxonox/ChatHistory.cc 2010-04-12 14:06:46 UTC (rev 6693)
@@ -32,21 +32,18 @@
namespace orxonox
{
#endif
- /* QUESTION */
- /* is this necessary? if yes uncomment please :P */
- //CreateFactory(ChatHistory);
/* constructor */
- #ifndef TEST
+#ifndef TEST
ChatHistory(BaseObject* creator) : BaseObject(creator)
- #else
+#else
ChatHistory::ChatHistory()
- #endif
+#endif
{
/* register the object */
- #ifndef TEST
+#ifndef TEST
RegisterObject(ChatHistory);
- #endif
+#endif
this->hist_log_enabled = true;
@@ -75,24 +72,30 @@
void ChatHistory::incomingChat(const std::string& message,
unsigned int senderID)
{
- /* QUESTION */
- /* sanity - check for valid senderID */
+ /* --> a) look up the actual name of the sender */
+ std::string text;
- /* TODO make a correct name */
- std::string name = "" + senderID; /* NOTE to be changed */
+#ifndef TEST
+ if (senderID != CLIENTID_UNKNOWN)
+ {
+ std::string name = "unknown";
+ PlayerInfo* player = PlayerManager::getInstance().getClient(senderID);
+ if (player)
+ name = player->getName();
- /* TODO */
- /* QUESTION */
- /* --> 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
- */
+ text = name + ": " + message;
+ }
+ else
+ text = message;
+#else
+ text = message;
+#endif
/* add the line to the history */
- this->chat_hist_addline( name + ": " + message );
+ this->chat_hist_addline( text );
/* add the line to the log */
- this->chat_hist_logline( name + ": " + message );
+ this->chat_hist_logline( text );
}
/* Synchronize logfile onto the hard drive */ /* MARK MARK */
@@ -124,15 +127,25 @@
/* open logfile */
int ChatHistory::chat_hist_openlog()
{
- /* QUESTION */
/* 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",
+#ifndef TEST
+ this->hist_logfile.open( PathConfig::getInstance().getLogPathString() +
+ "chatlog.log",
std::fstream::out | std::fstream::app );
+#else
+ this->hist_logfile.open( "/tmp/chatlog.log",
+ std::fstream::out | std::fstream::app );
+#endif
- /* QUESTION */
/* TODO check whether this works (not sure how you'd like it?) */
+ if( !this->hist_logfile )
+ { this->hist_log_enabled = false;
+#ifndef TEST
+ COUT(2) << "Warning: Could not open logfile." << std::endl;
+#endif
+ }
/* if it worked */
return 0;
Modified: code/branches/chat/src/orxonox/ChatHistory.h
===================================================================
--- code/branches/chat/src/orxonox/ChatHistory.h 2010-04-12 14:00:30 UTC (rev 6692)
+++ code/branches/chat/src/orxonox/ChatHistory.h 2010-04-12 14:06:46 UTC (rev 6693)
@@ -32,10 +32,11 @@
#include <iostream>
/* define this if you're unit testing */
-#define TEST 0
+#define TEST 1
#ifndef TEST
#include <core/BaseObject.h>
+#include <core/PathConfig.h>
#endif
#ifndef _ChatHistory_H__
@@ -49,19 +50,19 @@
#endif
/* constructor */
- #ifndef TEST
+#ifndef TEST
class _OrxonoxExport ChatHistory : public BaseObject, public ChatListener
- #else
+#else
class ChatHistory
- #endif
+#endif
{
public:
/* constructors, destructors */
- #ifndef TEST
+#ifndef TEST
ChatHistory(BaseObject* creator);
- #else
+#else
ChatHistory();
- #endif
+#endif
virtual ~ChatHistory();
More information about the Orxonox-commit
mailing list