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 <ChatHistory.h> |
---|
30 | |
---|
31 | namespace orxonox |
---|
32 | { |
---|
33 | /* is this necessary? if yes uncomment please :P */ |
---|
34 | //CreateFactory(ChatHistory); |
---|
35 | |
---|
36 | /* constructor */ |
---|
37 | ChatHistory(BaseObject* creator) : BaseObject(creator) |
---|
38 | { |
---|
39 | /* register the object */ |
---|
40 | RegisterObject(ChatHistory); |
---|
41 | |
---|
42 | /* Read setting for logfiles */ |
---|
43 | if( true ) /* NOTE Make this a check for the logfile setting */ |
---|
44 | this->chat_hist_openlog(); |
---|
45 | |
---|
46 | /* Read setting for maximum number of lines and set limit */ |
---|
47 | this->hist_maxlines = 200; /* NOTE to be changed, 200 is just for testing */ |
---|
48 | |
---|
49 | /* push starting line */ |
---|
50 | this->hist_buffer.push_front( "--- Logfile opened ---" ) |
---|
51 | } |
---|
52 | |
---|
53 | /* destructor */ |
---|
54 | virtual ChatHistory::~ChatHistory() |
---|
55 | { |
---|
56 | /* check if loggin is enabled */ |
---|
57 | /* y -> synchronize the logfile */ |
---|
58 | } |
---|
59 | |
---|
60 | /* react to incoming chat */ |
---|
61 | virtual void ChatHistory::incomingChat(const std::string& message, |
---|
62 | unsigned int senderID) |
---|
63 | { |
---|
64 | /* sanity - check for valid senderID */ |
---|
65 | /* sanity - check for valid string format */ |
---|
66 | |
---|
67 | /* format the message and senderID into a line */ |
---|
68 | std::string buf = "empty"; /* NOTE to be changed */ |
---|
69 | |
---|
70 | /* --> a) look up the actual name of the sender */ |
---|
71 | /* --> b) add sender name and string up with a separator |
---|
72 | * to make up the actual message |
---|
73 | */ |
---|
74 | |
---|
75 | /* add the line to the history */ |
---|
76 | this->chat_hist_addline( buf ); |
---|
77 | |
---|
78 | /* add the line to the log */ |
---|
79 | this->chat_hist_logline( buf ); |
---|
80 | } |
---|
81 | |
---|
82 | /* Synchronize logfile onto the hard drive */ /* MARK MARK */ |
---|
83 | int ChatHistory::syncLog(); |
---|
84 | |
---|
85 | /* add a line to this history */ |
---|
86 | int ChatHistory::chat_hist_addline( const std::string& toadd ); |
---|
87 | { |
---|
88 | /* push to the front of the history */ |
---|
89 | this->hist_buffer.push_front( toadd ); |
---|
90 | |
---|
91 | /* crop history at the end if it's too large */ |
---|
92 | this->hist_buffer.resize( this->hist_maxlines ); |
---|
93 | } |
---|
94 | |
---|
95 | /* log a line to a logfile */ |
---|
96 | int ChatHistory::chat_hist_logline( const std::string& toadd ) |
---|
97 | { |
---|
98 | /* TODO use already written class to batch write to file |
---|
99 | * so not every line gets written on its own |
---|
100 | */ |
---|
101 | /* output the line to the file if logging is enabled */ |
---|
102 | if( this->hist_log_enabled ) |
---|
103 | this->hist_logfile << buf << std::endl; |
---|
104 | } |
---|
105 | |
---|
106 | /* open logfile */ |
---|
107 | int ChatHistory::chat_hist_openlog() |
---|
108 | { |
---|
109 | /* TODO: find out the name of the file to log to via settings |
---|
110 | * and set the this->hist_logfile_path variable to it |
---|
111 | */ |
---|
112 | this->hist_logfile.open( "/tmp/setsomepath.txt", |
---|
113 | fstream::out | fstream::app ); |
---|
114 | |
---|
115 | /* TODO check whether this works (not sure how you'd like it?) */ |
---|
116 | |
---|
117 | /* if it worked */ |
---|
118 | return 0; |
---|
119 | } |
---|
120 | |
---|
121 | } |
---|