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