MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / handleCommand

Method handleCommand

source/game/StarChatProcessor.cpp:227–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

225}
226
227bool ChatProcessor::handleCommand(ChatReceivedMessage& message) {
228 if (!message.text.beginsWith("/")) {
229 return false;
230 } else if (message.text.beginsWith("//")) {
231 message.text = message.text.substr(1);
232 return false;
233 }
234
235 String commandLine = message.text.substr(1);
236 String command = commandLine.extract();
237
238 String response;
239
240 if (command == "nick") {
241 auto newNick = renick(message.fromConnection, commandLine.trim());
242 response = strf("Nick changed to {}", newNick);
243 } else if (command == "w") {
244 String target = commandLine.extract();
245 if (m_nicks.contains(target))
246 whisper(message.fromConnection, m_nicks.get(target), commandLine.trim());
247 else
248 response = strf("No such nick {}", target);
249 } else if (m_commandHandler) {
250 response = m_commandHandler(message.fromConnection, command, commandLine);
251 } else {
252 response = strf("No such command {}", command);
253 }
254
255 if (!response.empty()) {
256 m_clients.get(message.fromConnection).pendingMessages.append({
257 MessageContext(MessageContext::CommandResult),
258 ServerConnectionId,
259 connectionNick(ServerConnectionId),
260 response
261 });
262 }
263
264 return true;
265}
266
267}

Callers

nothing calls this directly

Calls 10

strfFunction · 0.85
MessageContextClass · 0.85
extractMethod · 0.80
beginsWithMethod · 0.45
substrMethod · 0.45
trimMethod · 0.45
containsMethod · 0.45
getMethod · 0.45
emptyMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected