Rev 1608 | Rev 1620 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1608 | Rev 1609 | ||
|---|---|---|---|
| Line 61... | Line 61... | ||
| 61 | } |
61 | } |
| 62 | 62 | ||
| 63 | void Console::InitializeDone() |
63 | void Console::InitializeDone() |
| 64 | { |
64 | { |
| 65 | Plugin::InitializeDone(); |
65 | Plugin::InitializeDone(); |
| - | 66 | ||
| - | 67 | this->ImportFunction("Console_DoAutocomplete"); |
|
| 66 | } |
68 | } |
| 67 | 69 | ||
| 68 | void Console::SlotOnNewData(net::ClientId client_id, net::ServerId server_id, type::Byteset data) |
70 | void Console::SlotOnNewData(net::ClientId client_id, net::ServerId server_id, type::Byteset data) |
| 69 | { |
71 | { |
| 70 | if (server_id != this->server_id_) |
72 | if (server_id != this->server_id_) |
| Line 73... | Line 75... | ||
| 73 | } |
75 | } |
| 74 | 76 | ||
| 75 | std::string str(data.ToCharString()); |
77 | std::string str(data.ToCharString()); |
| 76 | 78 | ||
| 77 | boost::algorithm::trim_right_if(str, boost::is_any_of("\r\n")); |
79 | boost::algorithm::trim_right_if(str, boost::is_any_of("\r\n")); |
| 78 | 80 | ||
| 79 | type::StringList parts; |
81 | type::StringList parts; |
| 80 | 82 | ||
| 81 | boost::algorithm::split(parts, str, boost::is_any_of(";"), boost::algorithm::token_compress_off); |
83 | boost::algorithm::split(parts, str, boost::is_any_of(";"), boost::algorithm::token_compress_off); |
| 82 | 84 | ||
| 83 | if (parts[0] == "A") // Autocomplete |
85 | if (parts[0] == "A") // Autocomplete |
| 84 | { |
86 | { |
| 85 | unsigned int arg_index = boost::lexical_cast<unsigned int>(parts[1]); |
87 | unsigned int arg_index = boost::lexical_cast<unsigned int>(parts[1]); |
| 86 | 88 | ||
| 87 | std::string result; |
89 | std::string result; |
| 88 | type::StringList arguments; |
90 | type::StringList arguments; |
| 89 | 91 | ||
| 90 | boost::algorithm::split(arguments, parts[2], boost::is_any_of(" "), boost::algorithm::token_compress_on); |
92 | boost::algorithm::split(arguments, parts[2], boost::is_any_of(" "), boost::algorithm::token_compress_on); |
| 91 | 93 | ||
| 92 | if (arg_index == 0) |
94 | if (arg_index == 0) |
| 93 | { |
95 | { |
| 94 | for (unsigned int n = 0; n < this->commands_.size(); n++) |
96 | for (unsigned int n = 0; n < this->commands_.size(); n++) |
| 95 | { |
97 | { |
| 96 | LOG. |
98 | //LOG.Debug(this->commands_[n]); |
| 97 | result += this->commands_[n] + "\n"; |
99 | result += this->commands_[n] + "\n"; |
| 98 | } |
100 | } |
| 99 | 101 | ||
| 100 | net::Manager::Instance()->SendTo(client_id, result); |
102 | net::Manager::Instance()->SendTo(client_id, result); |
| 101 | } |
103 | } |
| 102 | else |
104 | else |
| 103 | { |
105 | { |
| - | 106 | ArgumentListPointer call_arguments = ArgumentListPointer(new ArgumentList); |
|
| - | 107 | type::StringList arguments; |
|
| - | 108 | ||
| - | 109 | boost::algorithm::split(arguments, parts[2], boost::is_any_of(" "), boost::algorithm::token_compress_on); |
|
| - | 110 | ||
| - | 111 | for (unsigned int n = 0; n < arguments.size() && n <= arg_index; n++) |
|
| - | 112 | { |
|
| 104 |
|
113 | call_arguments->push_back(v8::String::New(arguments[n].data())); |
| - | 114 | } |
|
| - | 115 | ||
| - | 116 | this->Call(client_id, "Console_DoAutocomplete", call_arguments); |
|
| 105 | } |
117 | } |
| 106 | } |
118 | } |
| 107 | else if (parts[0] == "E") |
119 | else if (parts[0] == "E") |
| 108 | { |
120 | { |
| 109 | ArgumentListPointer call_arguments = ArgumentListPointer(new ArgumentList); |
121 | ArgumentListPointer call_arguments = ArgumentListPointer(new ArgumentList); |
| 110 | type::StringList arguments; |
122 | type::StringList arguments; |
| 111 | 123 | ||
| 112 | boost::algorithm::split(arguments, parts[1], boost::is_any_of(" "), boost::algorithm::token_compress_on); |
124 | boost::algorithm::split(arguments, parts[1], boost::is_any_of(" "), boost::algorithm::token_compress_on); |
| 113 | 125 | ||
| 114 | std::string command = arguments[0]; |
126 | std::string command = arguments[0]; |
| 115 | - | ||
| 116 | LOG.Debug("Command:" + command); |
- | |
| 117 | 127 | ||
| 118 | for (unsigned int n = 1; n < arguments.size(); n++) |
128 | for (unsigned int n = 1; n < arguments.size(); n++) |
| 119 | { |
129 | { |
| 120 | LOG.Debug("arg:" + arguments[n]); |
- | |
| 121 | call_arguments->push_back(v8::String::New(arguments[n].data())); |
130 | call_arguments->push_back(v8::String::New(arguments[n].data())); |
| 122 | } |
131 | } |
| 123 | 132 | ||
| 124 | this->Call(client_id, command, call_arguments); |
133 | this->Call(client_id, command, call_arguments); |
| 125 | } |
134 | } |
| Line 146... | Line 155... | ||
| 146 | } |
155 | } |
| 147 | } |
156 | } |
| 148 | 157 | ||
| 149 | void Console::ExecutionResult(std::string response, unsigned int request_id) |
158 | void Console::ExecutionResult(std::string response, unsigned int request_id) |
| 150 | { |
159 | { |
| 151 | LOG. |
160 | //LOG.Debug("ExecutionResult: response=" + response + ", request_id=" + boost::lexical_cast<std::string>(request_id)); |
| 152 | net::Manager::Instance()->SendTo(request_id, response); |
161 | net::Manager::Instance()->SendTo(request_id, response); |
| 153 | } |
162 | } |
| 154 | 163 | ||
| 155 | Value Console::Export_RegisterConsoleCommand(const v8::Arguments& args) |
164 | Value Console::Export_RegisterConsoleCommand(const v8::Arguments& args) |
| 156 | { |
165 | { |
| Line 161... | Line 170... | ||
| 161 | 170 | ||
| 162 | v8::String::AsciiValue command(args[0]); |
171 | v8::String::AsciiValue command(args[0]); |
| 163 | 172 | ||
| 164 | if (Console::ImportFunction(std::string(*command))) |
173 | if (Console::ImportFunction(std::string(*command))) |
| 165 | { |
174 | { |
| 166 | LOG.Debug(std::string(*command) + " registered |
175 | LOG.Debug(std::string(*command) + " registered successfully."); |
| 167 | Console::commands_.push_back(std::string(*command)); |
176 | Console::commands_.push_back(std::string(*command)); |
| 168 | return v8::Boolean::New(true); |
177 | return v8::Boolean::New(true); |
| 169 | } |
178 | } |
| 170 | 179 | ||
| 171 | LOG.Debug("Failed to register command!"); |
180 | LOG.Debug("Failed to register command!"); |