Rev 1627 | Rev 1644 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1627 | Rev 1642 | ||
|---|---|---|---|
| Line 30... | Line 30... | ||
| 30 | namespace atom { |
30 | namespace atom { |
| 31 | namespace vm { |
31 | namespace vm { |
| 32 | namespace plugin { |
32 | namespace plugin { |
| 33 | 33 | ||
| 34 | logging::Logger Console::LOG("vm::plugin::Console"); |
34 | logging::Logger Console::LOG("vm::plugin::Console"); |
| 35 |
|
35 | common::StringList Console::commands_; |
| 36 | 36 | ||
| 37 | Console::Console(boost::asio::io_service& io_service, unsigned int port) : Plugin(io_service) |
37 | Console::Console(boost::asio::io_service& io_service, unsigned int port) : Plugin(io_service) |
| 38 | { |
38 | { |
| 39 | this->name_ = "console"; |
39 | this->name_ = "console"; |
| 40 | 40 | ||
| Line 67... | Line 67... | ||
| 67 | 67 | ||
| 68 | this->ImportFunction("Console_DoAutocomplete"); |
68 | this->ImportFunction("Console_DoAutocomplete"); |
| 69 | this->ImportFunction("Console_PromptResponse"); |
69 | this->ImportFunction("Console_PromptResponse"); |
| 70 | } |
70 | } |
| 71 | 71 | ||
| 72 | void Console::SlotOnNewData(net::ClientId client_id, net::ServerId server_id, |
72 | void Console::SlotOnNewData(net::ClientId client_id, net::ServerId server_id, common::Byteset data) |
| 73 | { |
73 | { |
| 74 | if (server_id != this->server_id_) |
74 | if (server_id != this->server_id_) |
| 75 | { |
75 | { |
| 76 | return; |
76 | return; |
| 77 | } |
77 | } |
| Line 87... | Line 87... | ||
| 87 | } |
87 | } |
| 88 | 88 | ||
| 89 | this->io_service_.post(boost::bind(&Console::SlotOnNewStateHandler, this, client_id, server_id, client_state)); |
89 | this->io_service_.post(boost::bind(&Console::SlotOnNewStateHandler, this, client_id, server_id, client_state)); |
| 90 | } |
90 | } |
| 91 | 91 | ||
| 92 | void Console::SlotOnNewDataHandler(net::ClientId client_id, net::ServerId server_id, |
92 | void Console::SlotOnNewDataHandler(net::ClientId client_id, net::ServerId server_id, common::Byteset data) |
| 93 | { |
93 | { |
| 94 | v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext()); |
94 | v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext()); |
| 95 | 95 | ||
| 96 | LOG.Debug(std::string(__FUNCTION__) + " called!"); |
96 | LOG.Debug(std::string(__FUNCTION__) + " called!"); |
| 97 | 97 | ||
| 98 | std::string str(data.ToCharString()); |
98 | std::string str(data.ToCharString()); |
| 99 | 99 | ||
| 100 | boost::algorithm::trim_right_if(str, boost::is_any_of("\r\n")); |
100 | boost::algorithm::trim_right_if(str, boost::is_any_of("\r\n")); |
| 101 | 101 | ||
| 102 |
|
102 | common::StringList parts; |
| 103 | 103 | ||
| 104 | boost::algorithm::split(parts, str, boost::is_any_of(";"), boost::algorithm::token_compress_off); |
104 | boost::algorithm::split(parts, str, boost::is_any_of(";"), boost::algorithm::token_compress_off); |
| 105 | 105 | ||
| 106 | if (parts[0] == "A") // Autocomplete |
106 | if (parts[0] == "A") // Autocomplete |
| 107 | { |
107 | { |
| 108 | unsigned int arg_index = boost::lexical_cast<unsigned int>(parts[1]); |
108 | unsigned int arg_index = boost::lexical_cast<unsigned int>(parts[1]); |
| 109 | 109 | ||
| 110 | std::string result; |
110 | std::string result; |
| 111 |
|
111 | common::StringList arguments; |
| 112 | 112 | ||
| 113 | boost::algorithm::split(arguments, parts[2], boost::is_any_of(" "), boost::algorithm::token_compress_on); |
113 | boost::algorithm::split(arguments, parts[2], boost::is_any_of(" "), boost::algorithm::token_compress_on); |
| 114 | 114 | ||
| 115 | if (arg_index == 0) |
115 | if (arg_index == 0) |
| 116 | { |
116 | { |
| Line 123... | Line 123... | ||
| 123 | net::Manager::Instance()->SendTo(client_id, result); |
123 | net::Manager::Instance()->SendTo(client_id, result); |
| 124 | } |
124 | } |
| 125 | else |
125 | else |
| 126 | { |
126 | { |
| 127 | ArgumentListPointer call_arguments = ArgumentListPointer(new ArgumentList); |
127 | ArgumentListPointer call_arguments = ArgumentListPointer(new ArgumentList); |
| 128 |
|
128 | common::StringList arguments; |
| 129 | 129 | ||
| 130 | boost::algorithm::split(arguments, parts[2], boost::is_any_of(" "), boost::algorithm::token_compress_on); |
130 | boost::algorithm::split(arguments, parts[2], boost::is_any_of(" "), boost::algorithm::token_compress_on); |
| 131 | 131 | ||
| 132 | for (unsigned int n = 0; n < arguments.size() && n <= arg_index; n++) |
132 | for (unsigned int n = 0; n < arguments.size() && n <= arg_index; n++) |
| 133 | { |
133 | { |
| Line 138... | Line 138... | ||
| 138 | } |
138 | } |
| 139 | } |
139 | } |
| 140 | else if (parts[0] == "E") |
140 | else if (parts[0] == "E") |
| 141 | { |
141 | { |
| 142 | ArgumentListPointer call_arguments = ArgumentListPointer(new ArgumentList); |
142 | ArgumentListPointer call_arguments = ArgumentListPointer(new ArgumentList); |
| 143 |
|
143 | common::StringList arguments; |
| 144 | 144 | ||
| 145 | boost::algorithm::split(arguments, parts[1], boost::is_any_of(" "), boost::algorithm::token_compress_on); |
145 | boost::algorithm::split(arguments, parts[1], boost::is_any_of(" "), boost::algorithm::token_compress_on); |
| 146 | 146 | ||
| 147 | std::string command = arguments[0]; |
147 | std::string command = arguments[0]; |
| 148 | 148 | ||