[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 <deque> |
---|
| 30 | #include <string> |
---|
| 31 | #include <fstream> |
---|
| 32 | #include <iostream> |
---|
| 33 | |
---|
| 34 | #define TEST 0 |
---|
| 35 | |
---|
| 36 | #ifndef TEST |
---|
[6644] | 37 | #include <core/BaseObject.h> |
---|
[6688] | 38 | #endif |
---|
[6644] | 39 | |
---|
| 40 | #ifndef _ChatHistory_H__ |
---|
| 41 | #define _ChatHistory_H__ |
---|
| 42 | |
---|
[6688] | 43 | |
---|
[6644] | 44 | /* Class to implement chat history */ |
---|
[6688] | 45 | #ifndef TEST |
---|
[6644] | 46 | namespace orxonox |
---|
| 47 | { |
---|
[6688] | 48 | #endif |
---|
| 49 | |
---|
| 50 | /* constructor */ |
---|
| 51 | #ifndef TEST |
---|
[6644] | 52 | class _OrxonoxExport ChatHistory : public BaseObject, public ChatListener |
---|
[6688] | 53 | #else |
---|
| 54 | class ChatHistory |
---|
| 55 | #endif |
---|
[6644] | 56 | { |
---|
| 57 | public: |
---|
| 58 | /* constructors, destructors */ |
---|
[6688] | 59 | #ifndef TEST |
---|
[6644] | 60 | ChatHistory(BaseObject* creator); |
---|
[6688] | 61 | #else |
---|
| 62 | ChatHistory(); |
---|
| 63 | #endif |
---|
[6644] | 64 | virtual ~ChatHistory(); |
---|
| 65 | |
---|
| 66 | |
---|
[6688] | 67 | //protected: |
---|
[6644] | 68 | /** what to do with incoming chat |
---|
| 69 | * |
---|
| 70 | * \param message The incoming message |
---|
| 71 | * \param senderID Identification number of the sender |
---|
| 72 | */ |
---|
| 73 | virtual void incomingChat(const std::string& message, |
---|
| 74 | unsigned int senderID); |
---|
| 75 | |
---|
| 76 | /** Synchronize logfile onto the hard drive |
---|
| 77 | * |
---|
| 78 | * \return 0 for success, other for error |
---|
| 79 | */ |
---|
| 80 | int syncLog(); |
---|
[6688] | 81 | |
---|
| 82 | /** debug-print */ |
---|
| 83 | void debug_printhist(); |
---|
[6644] | 84 | |
---|
| 85 | private: |
---|
| 86 | /* FIELDS */ |
---|
| 87 | /** Vector to store the history in */ |
---|
[6688] | 88 | std::deque<std::string> hist_buffer; |
---|
[6644] | 89 | |
---|
| 90 | /** Maximum number of lines stored in this history */ |
---|
| 91 | unsigned int hist_maxlines; |
---|
| 92 | |
---|
| 93 | /** is logging enabled? */ |
---|
| 94 | bool hist_log_enabled; |
---|
| 95 | |
---|
| 96 | /** path of logfile on the file system */ |
---|
| 97 | std::string hist_logfile_path; |
---|
| 98 | |
---|
| 99 | /** Output file stream for logfile */ |
---|
[6688] | 100 | std::ofstream hist_logfile; |
---|
[6644] | 101 | |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | /* METHODS */ |
---|
| 106 | /** Append line to chat history |
---|
| 107 | * |
---|
| 108 | * \param toadd The line to add to the history |
---|
| 109 | * \return 0 for success, other for error TODO: Throw exception |
---|
| 110 | */ |
---|
| 111 | int chat_hist_addline( const std::string& toadd ); |
---|
| 112 | |
---|
| 113 | /** Append line to logfile |
---|
| 114 | * |
---|
| 115 | * \param toadd The line to add to the logfile |
---|
| 116 | * \return 0 for success, other for error TODO: Throw exception |
---|
| 117 | */ |
---|
| 118 | int chat_hist_logline( const std::string& toadd ); |
---|
| 119 | |
---|
| 120 | /** open logfile to log to |
---|
| 121 | * |
---|
| 122 | * \return 0 for success,s other for error |
---|
| 123 | */ |
---|
| 124 | int chat_hist_openlog(); |
---|
[6688] | 125 | |
---|
| 126 | |
---|
| 127 | /** close logfile */ |
---|
| 128 | void chat_hist_closelog(); |
---|
| 129 | }; |
---|
| 130 | |
---|
| 131 | #ifndef TEST |
---|
[6644] | 132 | } |
---|
[6688] | 133 | #endif |
---|
[6644] | 134 | |
---|
| 135 | |
---|
| 136 | #endif /* _ChatHistory_H__ */ |
---|