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