Rev 1665 | Rev 1675 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1665 | Rev 1674 | ||
|---|---|---|---|
| Line 109... | Line 109... | ||
| 109 | } |
109 | } |
| 110 | 110 | ||
| 111 | private: |
111 | private: |
| 112 | net::ClientId client_id_; |
112 | net::ClientId client_id_; |
| 113 | std::string prompt_; |
113 | std::string prompt_; |
| - | 114 | std::vector<unsigned char> buffer_; |
|
| 114 | 115 | ||
| 115 | void SlotOnNewStateHandler(net::ClientId client_id, net::ServerId server_id, net::ClientState client_state) |
116 | void SlotOnNewStateHandler(net::ClientId client_id, net::ServerId server_id, net::ClientState client_state) |
| 116 | { |
117 | { |
| 117 | if (client_state != net::CLIENT_STATE_CONNECTED) |
118 | if (client_state != net::CLIENT_STATE_CONNECTED) |
| 118 | { |
119 | { |
| Line 124... | Line 125... | ||
| 124 | } |
125 | } |
| 125 | } |
126 | } |
| 126 | 127 | ||
| 127 | void SlotOnNewDataHandler(net::ClientId client_id, net::ServerId server_id, common::Byteset data) |
128 | void SlotOnNewDataHandler(net::ClientId client_id, net::ServerId server_id, common::Byteset data) |
| 128 | { |
129 | { |
| - | 130 | for (unsigned int n = 0; n < data.GetSize(); n++) |
|
| - | 131 | { |
|
| 129 |
|
132 | this->buffer_.push_back(data[n]); |
| - | 133 | } |
|
| 130 | 134 | ||
| 131 | while ( |
135 | while (this->buffer_.size() >= 8) |
| 132 | { |
136 | { |
| 133 | std::string command = |
137 | std::string command = ""; |
| - | 138 | command += (char)this->buffer_[0]; |
|
| - | 139 | command += (char)this->buffer_[1]; |
|
| - | 140 | command += (char)this->buffer_[2]; |
|
| - | 141 | command += (char)this->buffer_[3]; |
|
| - | 142 | ||
| - | 143 | std::string payload_length_str = ""; |
|
| - | 144 | payload_length_str += (char)this->buffer_[4]; |
|
| - | 145 | payload_length_str += (char)this->buffer_[5]; |
|
| - | 146 | payload_length_str += (char)this->buffer_[6]; |
|
| - | 147 | payload_length_str += (char)this->buffer_[7]; |
|
| - | 148 | ||
| 134 | unsigned int payload_length = boost::lexical_cast<unsigned int>( |
149 | unsigned int payload_length = boost::lexical_cast<unsigned int>(payload_length_str); |
| 135 | 150 | ||
| - | 151 | if (this->buffer_.size() - 8 < payload_length) |
|
| - | 152 | { |
|
| - | 153 | return; |
|
| - | 154 | } |
|
| - | 155 | ||
| - | 156 | std::string payload = ""; |
|
| - | 157 | for (unsigned int n = 8; n < payload_length + 8; n++) |
|
| - | 158 | { |
|
| - | 159 | payload += (char)this->buffer_[n]; |
|
| - | 160 | } |
|
| - | 161 | ||
| - | 162 | this->buffer_.erase(this->buffer_.begin(), this->buffer_.begin() + payload_length + 8); |
|
| - | 163 | ||
| 136 | if (command == "TEXT") |
164 | if (command == "TEXT") |
| 137 | { |
165 | { |
| 138 | std::cout << |
166 | std::cout << payload << std::flush; |
| 139 | } |
167 | } |
| 140 | else if (command == "PROM") |
168 | else if (command == "PROM") |
| 141 | { |
169 | { |
| 142 | this->prompt_ = |
170 | this->prompt_ = payload; |
| 143 | on_message_condition.notify_all(); |
171 | on_message_condition.notify_all(); |
| 144 | } |
172 | } |
| 145 | else if (command == "COMP") |
173 | else if (command == "COMP") |
| 146 | { |
174 | { |
| 147 | autocomplete_list.clear(); |
175 | autocomplete_list.clear(); |
| 148 | - | ||
| 149 | if (payload_length > 0) |
- | |
| 150 | { |
- | |
| 151 | std::string payload = s.substr(8, payload_length - 1); |
- | |
| 152 | 176 | ||
| 153 | if (payload.length() > 0) |
177 | if (payload.length() > 0) |
| 154 | { |
178 | { |
| 155 | boost::algorithm::split(autocomplete_list, payload, boost::is_any_of("\n"), boost::algorithm::token_compress_on); |
179 | boost::algorithm::split(autocomplete_list, payload, boost::is_any_of("\n"), boost::algorithm::token_compress_on); |
| 156 | } |
- | |
| 157 | } |
180 | } |
| 158 | 181 | ||
| 159 | on_message_condition.notify_all(); |
182 | on_message_condition.notify_all(); |
| 160 | } |
183 | } |
| 161 | else |
184 | else |
| 162 | { |
185 | { |
| 163 | std::cerr << " |
186 | std::cerr << "Could not parse package." << std::endl; |
| 164 | finish = true; |
187 | finish = true; |
| 165 | on_message_condition.notify_all(); |
188 | on_message_condition.notify_all(); |
| 166 | break; |
189 | break; |
| 167 | } |
190 | } |
| 168 | - | ||
| 169 | if (8 + payload_length >= s.length()) |
- | |
| 170 | { |
- | |
| 171 | break; |
- | |
| 172 | } |
- | |
| 173 | - | ||
| 174 | s = s.substr(8 + payload_length); |
- | |
| 175 | } |
191 | } |
| 176 | } |
192 | } |
| 177 | }; |
193 | }; |
| 178 | 194 | ||
| 179 | ConsoleClient::Pointer cc; |
195 | ConsoleClient::Pointer cc; |