MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ReceiveCommand

Method ReceiveCommand

src/network/network_command.cpp:374–388  ·  view source on GitHub ↗

* Receives a command from the network. * @param p the packet to read from. * @param cp the struct to write the data to. * @return An error message, or std::nullopt there has been no error. */

Source from the content-addressed store, hash-verified

372 * @return An error message, or std::nullopt there has been no error.
373 */
374std::optional<std::string_view> NetworkGameSocketHandler::ReceiveCommand(Packet &p, CommandPacket &cp)
375{
376 cp.company = (CompanyID)p.Recv_uint8();
377 cp.cmd = static_cast<Commands>(p.Recv_uint16());
378 if (!IsValidCommand(cp.cmd)) return "invalid command";
379 if (GetCommandFlags(cp.cmd).Test(CommandFlag::Offline)) return "single-player only command";
380 cp.err_msg = p.Recv_uint16();
381 cp.data = _cmd_dispatch[cp.cmd].Sanitize(p.Recv_buffer());
382
383 uint8_t callback = p.Recv_uint8();
384 if (callback >= _callback_table.size() || _cmd_dispatch[cp.cmd].Unpack[callback] == nullptr) return "invalid callback";
385
386 cp.callback = _callback_table[callback];
387 return std::nullopt;
388}
389
390/**
391 * Sends a command over the network.

Callers 2

Calls 7

IsValidCommandFunction · 0.85
Recv_uint8Method · 0.80
Recv_uint16Method · 0.80
TestMethod · 0.80
Recv_bufferMethod · 0.80
GetCommandFlagsFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected