serverpackethandler.cpp 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812
  1. /*
  2. Minetest
  3. Copyright (C) 2015 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #include "chatmessage.h"
  17. #include "server.h"
  18. #include "log.h"
  19. #include "emerge.h"
  20. #include "mapblock.h"
  21. #include "modchannels.h"
  22. #include "nodedef.h"
  23. #include "remoteplayer.h"
  24. #include "rollback_interface.h"
  25. #include "scripting_server.h"
  26. #include "settings.h"
  27. #include "tool.h"
  28. #include "version.h"
  29. #include "network/connection.h"
  30. #include "network/networkprotocol.h"
  31. #include "network/serveropcodes.h"
  32. #include "server/player_sao.h"
  33. #include "server/serverinventorymgr.h"
  34. #include "util/auth.h"
  35. #include "util/base64.h"
  36. #include "util/pointedthing.h"
  37. #include "util/serialize.h"
  38. #include "util/srp.h"
  39. void Server::handleCommand_Deprecated(NetworkPacket* pkt)
  40. {
  41. infostream << "Server: " << toServerCommandTable[pkt->getCommand()].name
  42. << " not supported anymore" << std::endl;
  43. }
  44. void Server::handleCommand_Init(NetworkPacket* pkt)
  45. {
  46. if(pkt->getSize() < 1)
  47. return;
  48. session_t peer_id = pkt->getPeerId();
  49. RemoteClient *client = getClient(peer_id, CS_Created);
  50. std::string addr_s;
  51. try {
  52. Address address = getPeerAddress(peer_id);
  53. addr_s = address.serializeString();
  54. }
  55. catch (con::PeerNotFoundException &e) {
  56. /*
  57. * no peer for this packet found
  58. * most common reason is peer timeout, e.g. peer didn't
  59. * respond for some time, your server was overloaded or
  60. * things like that.
  61. */
  62. infostream << "Server::ProcessData(): Canceling: peer " << peer_id <<
  63. " not found" << std::endl;
  64. return;
  65. }
  66. // If net_proto_version is set, this client has already been handled
  67. if (client->getState() > CS_Created) {
  68. verbosestream << "Server: Ignoring multiple TOSERVER_INITs from " <<
  69. addr_s << " (peer_id=" << peer_id << ")" << std::endl;
  70. return;
  71. }
  72. verbosestream << "Server: Got TOSERVER_INIT from " << addr_s <<
  73. " (peer_id=" << peer_id << ")" << std::endl;
  74. // Do not allow multiple players in simple singleplayer mode.
  75. // This isn't a perfect way to do it, but will suffice for now
  76. if (m_simple_singleplayer_mode && m_clients.getClientIDs().size() > 1) {
  77. infostream << "Server: Not allowing another client (" << addr_s <<
  78. ") to connect in simple singleplayer mode" << std::endl;
  79. DenyAccess(peer_id, SERVER_ACCESSDENIED_SINGLEPLAYER);
  80. return;
  81. }
  82. // First byte after command is maximum supported
  83. // serialization version
  84. u8 client_max;
  85. u16 supp_compr_modes;
  86. u16 min_net_proto_version = 0;
  87. u16 max_net_proto_version;
  88. std::string playerName;
  89. *pkt >> client_max >> supp_compr_modes >> min_net_proto_version
  90. >> max_net_proto_version >> playerName;
  91. u8 our_max = SER_FMT_VER_HIGHEST_READ;
  92. // Use the highest version supported by both
  93. u8 depl_serial_v = std::min(client_max, our_max);
  94. // If it's lower than the lowest supported, give up.
  95. if (depl_serial_v < SER_FMT_VER_LOWEST_READ)
  96. depl_serial_v = SER_FMT_VER_INVALID;
  97. if (depl_serial_v == SER_FMT_VER_INVALID) {
  98. actionstream << "Server: A mismatched client tried to connect from " <<
  99. addr_s << " ser_fmt_max=" << (int)client_max << std::endl;
  100. DenyAccess(peer_id, SERVER_ACCESSDENIED_WRONG_VERSION);
  101. return;
  102. }
  103. client->setPendingSerializationVersion(depl_serial_v);
  104. /*
  105. Read and check network protocol version
  106. */
  107. u16 net_proto_version = 0;
  108. // Figure out a working version if it is possible at all
  109. if (max_net_proto_version >= SERVER_PROTOCOL_VERSION_MIN ||
  110. min_net_proto_version <= SERVER_PROTOCOL_VERSION_MAX) {
  111. // If maximum is larger than our maximum, go with our maximum
  112. if (max_net_proto_version > SERVER_PROTOCOL_VERSION_MAX)
  113. net_proto_version = SERVER_PROTOCOL_VERSION_MAX;
  114. // Else go with client's maximum
  115. else
  116. net_proto_version = max_net_proto_version;
  117. }
  118. verbosestream << "Server: " << addr_s << ": Protocol version: min: "
  119. << min_net_proto_version << ", max: " << max_net_proto_version
  120. << ", chosen: " << net_proto_version << std::endl;
  121. client->net_proto_version = net_proto_version;
  122. if ((g_settings->getBool("strict_protocol_version_checking") &&
  123. net_proto_version != LATEST_PROTOCOL_VERSION) ||
  124. net_proto_version < SERVER_PROTOCOL_VERSION_MIN ||
  125. net_proto_version > SERVER_PROTOCOL_VERSION_MAX) {
  126. actionstream << "Server: A mismatched client tried to connect from " <<
  127. addr_s << " proto_max=" << (int)max_net_proto_version << std::endl;
  128. DenyAccess(peer_id, SERVER_ACCESSDENIED_WRONG_VERSION);
  129. return;
  130. }
  131. /*
  132. Validate player name
  133. */
  134. const char* playername = playerName.c_str();
  135. size_t pns = playerName.size();
  136. if (pns == 0 || pns > PLAYERNAME_SIZE) {
  137. actionstream << "Server: Player with " <<
  138. ((pns > PLAYERNAME_SIZE) ? "a too long" : "an empty") <<
  139. " name tried to connect from " << addr_s << std::endl;
  140. DenyAccess(peer_id, SERVER_ACCESSDENIED_WRONG_NAME);
  141. return;
  142. }
  143. if (!string_allowed(playerName, PLAYERNAME_ALLOWED_CHARS)) {
  144. actionstream << "Server: Player with an invalid name tried to connect "
  145. "from " << addr_s << std::endl;
  146. DenyAccess(peer_id, SERVER_ACCESSDENIED_WRONG_CHARS_IN_NAME);
  147. return;
  148. }
  149. m_clients.setPlayerName(peer_id, playername);
  150. //TODO (later) case insensitivity
  151. std::string legacyPlayerNameCasing = playerName;
  152. if (!isSingleplayer() && strcasecmp(playername, "singleplayer") == 0) {
  153. actionstream << "Server: Player with the name \"singleplayer\" tried "
  154. "to connect from " << addr_s << std::endl;
  155. DenyAccess(peer_id, SERVER_ACCESSDENIED_WRONG_NAME);
  156. return;
  157. }
  158. {
  159. std::string reason;
  160. if (m_script->on_prejoinplayer(playername, addr_s, &reason)) {
  161. actionstream << "Server: Player with the name \"" << playerName <<
  162. "\" tried to connect from " << addr_s <<
  163. " but it was disallowed for the following reason: " << reason <<
  164. std::endl;
  165. DenyAccess(peer_id, SERVER_ACCESSDENIED_CUSTOM_STRING, reason);
  166. return;
  167. }
  168. }
  169. infostream << "Server: New connection: \"" << playerName << "\" from " <<
  170. addr_s << " (peer_id=" << peer_id << ")" << std::endl;
  171. // Enforce user limit.
  172. // Don't enforce for users that have some admin right or mod permits it.
  173. if (m_clients.isUserLimitReached() &&
  174. playername != g_settings->get("name") &&
  175. !m_script->can_bypass_userlimit(playername, addr_s)) {
  176. actionstream << "Server: " << playername << " tried to join from " <<
  177. addr_s << ", but there are already max_users=" <<
  178. g_settings->getU16("max_users") << " players." << std::endl;
  179. DenyAccess(peer_id, SERVER_ACCESSDENIED_TOO_MANY_USERS);
  180. return;
  181. }
  182. /*
  183. Compose auth methods for answer
  184. */
  185. std::string encpwd; // encrypted Password field for the user
  186. bool has_auth = m_script->getAuth(playername, &encpwd, NULL);
  187. u32 auth_mechs = 0;
  188. client->chosen_mech = AUTH_MECHANISM_NONE;
  189. if (has_auth) {
  190. std::vector<std::string> pwd_components = str_split(encpwd, '#');
  191. if (pwd_components.size() == 4) {
  192. if (pwd_components[1] == "1") { // 1 means srp
  193. auth_mechs |= AUTH_MECHANISM_SRP;
  194. client->enc_pwd = encpwd;
  195. } else {
  196. actionstream << "User " << playername << " tried to log in, "
  197. "but password field was invalid (unknown mechcode)." <<
  198. std::endl;
  199. DenyAccess(peer_id, SERVER_ACCESSDENIED_SERVER_FAIL);
  200. return;
  201. }
  202. } else if (base64_is_valid(encpwd)) {
  203. auth_mechs |= AUTH_MECHANISM_LEGACY_PASSWORD;
  204. client->enc_pwd = encpwd;
  205. } else {
  206. actionstream << "User " << playername << " tried to log in, but "
  207. "password field was invalid (invalid base64)." << std::endl;
  208. DenyAccess(peer_id, SERVER_ACCESSDENIED_SERVER_FAIL);
  209. return;
  210. }
  211. } else {
  212. std::string default_password = g_settings->get("default_password");
  213. if (default_password.length() == 0) {
  214. auth_mechs |= AUTH_MECHANISM_FIRST_SRP;
  215. } else {
  216. // Take care of default passwords.
  217. client->enc_pwd = get_encoded_srp_verifier(playerName, default_password);
  218. auth_mechs |= AUTH_MECHANISM_SRP;
  219. // Allocate player in db, but only on successful login.
  220. client->create_player_on_auth_success = true;
  221. }
  222. }
  223. /*
  224. Answer with a TOCLIENT_HELLO
  225. */
  226. verbosestream << "Sending TOCLIENT_HELLO with auth method field: "
  227. << auth_mechs << std::endl;
  228. NetworkPacket resp_pkt(TOCLIENT_HELLO,
  229. 1 + 4 + legacyPlayerNameCasing.size(), peer_id);
  230. u16 depl_compress_mode = NETPROTO_COMPRESSION_NONE;
  231. resp_pkt << depl_serial_v << depl_compress_mode << net_proto_version
  232. << auth_mechs << legacyPlayerNameCasing;
  233. Send(&resp_pkt);
  234. client->allowed_auth_mechs = auth_mechs;
  235. client->setDeployedCompressionMode(depl_compress_mode);
  236. m_clients.event(peer_id, CSE_Hello);
  237. }
  238. void Server::handleCommand_Init2(NetworkPacket* pkt)
  239. {
  240. session_t peer_id = pkt->getPeerId();
  241. verbosestream << "Server: Got TOSERVER_INIT2 from " << peer_id << std::endl;
  242. m_clients.event(peer_id, CSE_GotInit2);
  243. u16 protocol_version = m_clients.getProtocolVersion(peer_id);
  244. std::string lang;
  245. if (pkt->getSize() > 0)
  246. *pkt >> lang;
  247. /*
  248. Send some initialization data
  249. */
  250. infostream << "Server: Sending content to " << getPlayerName(peer_id) <<
  251. std::endl;
  252. // Send item definitions
  253. SendItemDef(peer_id, m_itemdef, protocol_version);
  254. // Send node definitions
  255. SendNodeDef(peer_id, m_nodedef, protocol_version);
  256. m_clients.event(peer_id, CSE_SetDefinitionsSent);
  257. // Send media announcement
  258. sendMediaAnnouncement(peer_id, lang);
  259. RemoteClient *client = getClient(peer_id, CS_InitDone);
  260. // Keep client language for server translations
  261. client->setLangCode(lang);
  262. // Send active objects
  263. {
  264. PlayerSAO *sao = getPlayerSAO(peer_id);
  265. if (sao)
  266. SendActiveObjectRemoveAdd(client, sao);
  267. }
  268. // Send detached inventories
  269. sendDetachedInventories(peer_id, false);
  270. // Send player movement settings
  271. SendMovement(peer_id);
  272. // Send time of day
  273. u16 time = m_env->getTimeOfDay();
  274. float time_speed = g_settings->getFloat("time_speed");
  275. SendTimeOfDay(peer_id, time, time_speed);
  276. SendCSMRestrictionFlags(peer_id);
  277. // Warnings about protocol version can be issued here
  278. if (client->net_proto_version < LATEST_PROTOCOL_VERSION) {
  279. SendChatMessage(peer_id, ChatMessage(CHATMESSAGE_TYPE_SYSTEM,
  280. L"# Server: WARNING: YOUR CLIENT'S VERSION MAY NOT BE FULLY COMPATIBLE "
  281. L"WITH THIS SERVER!"));
  282. }
  283. }
  284. void Server::handleCommand_RequestMedia(NetworkPacket* pkt)
  285. {
  286. std::vector<std::string> tosend;
  287. u16 numfiles;
  288. *pkt >> numfiles;
  289. session_t peer_id = pkt->getPeerId();
  290. infostream << "Sending " << numfiles << " files to " <<
  291. getPlayerName(peer_id) << std::endl;
  292. verbosestream << "TOSERVER_REQUEST_MEDIA: " << std::endl;
  293. for (u16 i = 0; i < numfiles; i++) {
  294. std::string name;
  295. *pkt >> name;
  296. tosend.push_back(name);
  297. verbosestream << "TOSERVER_REQUEST_MEDIA: requested file "
  298. << name << std::endl;
  299. }
  300. sendRequestedMedia(peer_id, tosend);
  301. }
  302. void Server::handleCommand_ClientReady(NetworkPacket* pkt)
  303. {
  304. session_t peer_id = pkt->getPeerId();
  305. PlayerSAO* playersao = StageTwoClientInit(peer_id);
  306. if (playersao == NULL) {
  307. errorstream << "TOSERVER_CLIENT_READY stage 2 client init failed "
  308. "peer_id=" << peer_id << std::endl;
  309. DisconnectPeer(peer_id);
  310. return;
  311. }
  312. if (pkt->getSize() < 8) {
  313. errorstream << "TOSERVER_CLIENT_READY client sent inconsistent data, "
  314. "disconnecting peer_id: " << peer_id << std::endl;
  315. DisconnectPeer(peer_id);
  316. return;
  317. }
  318. u8 major_ver, minor_ver, patch_ver, reserved;
  319. std::string full_ver;
  320. *pkt >> major_ver >> minor_ver >> patch_ver >> reserved >> full_ver;
  321. m_clients.setClientVersion(peer_id, major_ver, minor_ver, patch_ver,
  322. full_ver);
  323. if (pkt->getRemainingBytes() >= 2)
  324. *pkt >> playersao->getPlayer()->formspec_version;
  325. const std::vector<std::string> &players = m_clients.getPlayerNames();
  326. NetworkPacket list_pkt(TOCLIENT_UPDATE_PLAYER_LIST, 0, peer_id);
  327. list_pkt << (u8) PLAYER_LIST_INIT << (u16) players.size();
  328. for (const std::string &player: players) {
  329. list_pkt << player;
  330. }
  331. m_clients.send(peer_id, 0, &list_pkt, true);
  332. NetworkPacket notice_pkt(TOCLIENT_UPDATE_PLAYER_LIST, 0, PEER_ID_INEXISTENT);
  333. // (u16) 1 + std::string represents a pseudo vector serialization representation
  334. notice_pkt << (u8) PLAYER_LIST_ADD << (u16) 1 << std::string(playersao->getPlayer()->getName());
  335. m_clients.sendToAll(&notice_pkt);
  336. m_clients.event(peer_id, CSE_SetClientReady);
  337. s64 last_login;
  338. m_script->getAuth(playersao->getPlayer()->getName(), nullptr, nullptr, &last_login);
  339. m_script->on_joinplayer(playersao, last_login);
  340. // Send shutdown timer if shutdown has been scheduled
  341. if (m_shutdown_state.isTimerRunning()) {
  342. SendChatMessage(peer_id, m_shutdown_state.getShutdownTimerMessage());
  343. }
  344. }
  345. void Server::handleCommand_GotBlocks(NetworkPacket* pkt)
  346. {
  347. if (pkt->getSize() < 1)
  348. return;
  349. /*
  350. [0] u16 command
  351. [2] u8 count
  352. [3] v3s16 pos_0
  353. [3+6] v3s16 pos_1
  354. ...
  355. */
  356. u8 count;
  357. *pkt >> count;
  358. RemoteClient *client = getClient(pkt->getPeerId());
  359. if ((s16)pkt->getSize() < 1 + (int)count * 6) {
  360. throw con::InvalidIncomingDataException
  361. ("GOTBLOCKS length is too short");
  362. }
  363. for (u16 i = 0; i < count; i++) {
  364. v3s16 p;
  365. *pkt >> p;
  366. client->GotBlock(p);
  367. }
  368. }
  369. void Server::process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao,
  370. NetworkPacket *pkt)
  371. {
  372. if (pkt->getRemainingBytes() < 12 + 12 + 4 + 4 + 4 + 1 + 1)
  373. return;
  374. v3s32 ps, ss;
  375. s32 f32pitch, f32yaw;
  376. u8 f32fov;
  377. *pkt >> ps;
  378. *pkt >> ss;
  379. *pkt >> f32pitch;
  380. *pkt >> f32yaw;
  381. f32 pitch = (f32)f32pitch / 100.0f;
  382. f32 yaw = (f32)f32yaw / 100.0f;
  383. u32 keyPressed = 0;
  384. // default behavior (in case an old client doesn't send these)
  385. f32 fov = 0;
  386. u8 wanted_range = 0;
  387. *pkt >> keyPressed;
  388. *pkt >> f32fov;
  389. fov = (f32)f32fov / 80.0f;
  390. *pkt >> wanted_range;
  391. v3f position((f32)ps.X / 100.0f, (f32)ps.Y / 100.0f, (f32)ps.Z / 100.0f);
  392. v3f speed((f32)ss.X / 100.0f, (f32)ss.Y / 100.0f, (f32)ss.Z / 100.0f);
  393. pitch = modulo360f(pitch);
  394. yaw = wrapDegrees_0_360(yaw);
  395. playersao->setBasePosition(position);
  396. player->setSpeed(speed);
  397. playersao->setLookPitch(pitch);
  398. playersao->setPlayerYaw(yaw);
  399. playersao->setFov(fov);
  400. playersao->setWantedRange(wanted_range);
  401. player->keyPressed = keyPressed;
  402. player->control.up = (keyPressed & (0x1 << 0));
  403. player->control.down = (keyPressed & (0x1 << 1));
  404. player->control.left = (keyPressed & (0x1 << 2));
  405. player->control.right = (keyPressed & (0x1 << 3));
  406. player->control.jump = (keyPressed & (0x1 << 4));
  407. player->control.aux1 = (keyPressed & (0x1 << 5));
  408. player->control.sneak = (keyPressed & (0x1 << 6));
  409. player->control.dig = (keyPressed & (0x1 << 7));
  410. player->control.place = (keyPressed & (0x1 << 8));
  411. player->control.zoom = (keyPressed & (0x1 << 9));
  412. if (playersao->checkMovementCheat()) {
  413. // Call callbacks
  414. m_script->on_cheat(playersao, "moved_too_fast");
  415. SendMovePlayer(pkt->getPeerId());
  416. }
  417. }
  418. void Server::handleCommand_PlayerPos(NetworkPacket* pkt)
  419. {
  420. session_t peer_id = pkt->getPeerId();
  421. RemotePlayer *player = m_env->getPlayer(peer_id);
  422. if (player == NULL) {
  423. errorstream <<
  424. "Server::ProcessData(): Canceling: No player for peer_id=" <<
  425. peer_id << " disconnecting peer!" << std::endl;
  426. DisconnectPeer(peer_id);
  427. return;
  428. }
  429. PlayerSAO *playersao = player->getPlayerSAO();
  430. if (playersao == NULL) {
  431. errorstream <<
  432. "Server::ProcessData(): Canceling: No player object for peer_id=" <<
  433. peer_id << " disconnecting peer!" << std::endl;
  434. DisconnectPeer(peer_id);
  435. return;
  436. }
  437. // If player is dead we don't care of this packet
  438. if (playersao->isDead()) {
  439. verbosestream << "TOSERVER_PLAYERPOS: " << player->getName()
  440. << " is dead. Ignoring packet";
  441. return;
  442. }
  443. process_PlayerPos(player, playersao, pkt);
  444. }
  445. void Server::handleCommand_DeletedBlocks(NetworkPacket* pkt)
  446. {
  447. if (pkt->getSize() < 1)
  448. return;
  449. /*
  450. [0] u16 command
  451. [2] u8 count
  452. [3] v3s16 pos_0
  453. [3+6] v3s16 pos_1
  454. ...
  455. */
  456. u8 count;
  457. *pkt >> count;
  458. RemoteClient *client = getClient(pkt->getPeerId());
  459. if ((s16)pkt->getSize() < 1 + (int)count * 6) {
  460. throw con::InvalidIncomingDataException
  461. ("DELETEDBLOCKS length is too short");
  462. }
  463. for (u16 i = 0; i < count; i++) {
  464. v3s16 p;
  465. *pkt >> p;
  466. client->SetBlockNotSent(p);
  467. }
  468. }
  469. void Server::handleCommand_InventoryAction(NetworkPacket* pkt)
  470. {
  471. session_t peer_id = pkt->getPeerId();
  472. RemotePlayer *player = m_env->getPlayer(peer_id);
  473. if (player == NULL) {
  474. errorstream <<
  475. "Server::ProcessData(): Canceling: No player for peer_id=" <<
  476. peer_id << " disconnecting peer!" << std::endl;
  477. DisconnectPeer(peer_id);
  478. return;
  479. }
  480. PlayerSAO *playersao = player->getPlayerSAO();
  481. if (playersao == NULL) {
  482. errorstream <<
  483. "Server::ProcessData(): Canceling: No player object for peer_id=" <<
  484. peer_id << " disconnecting peer!" << std::endl;
  485. DisconnectPeer(peer_id);
  486. return;
  487. }
  488. // Strip command and create a stream
  489. std::string datastring(pkt->getString(0), pkt->getSize());
  490. verbosestream << "TOSERVER_INVENTORY_ACTION: data=" << datastring
  491. << std::endl;
  492. std::istringstream is(datastring, std::ios_base::binary);
  493. // Create an action
  494. std::unique_ptr<InventoryAction> a(InventoryAction::deSerialize(is));
  495. if (!a) {
  496. infostream << "TOSERVER_INVENTORY_ACTION: "
  497. << "InventoryAction::deSerialize() returned NULL"
  498. << std::endl;
  499. return;
  500. }
  501. // If something goes wrong, this player is to blame
  502. RollbackScopeActor rollback_scope(m_rollback,
  503. std::string("player:")+player->getName());
  504. /*
  505. Note: Always set inventory not sent, to repair cases
  506. where the client made a bad prediction.
  507. */
  508. const bool player_has_interact = checkPriv(player->getName(), "interact");
  509. auto check_inv_access = [player, player_has_interact] (
  510. const InventoryLocation &loc) -> bool {
  511. if (loc.type == InventoryLocation::CURRENT_PLAYER)
  512. return false; // Only used internally on the client, never sent
  513. if (loc.type == InventoryLocation::PLAYER) {
  514. // Allow access to own inventory in all cases
  515. return loc.name == player->getName();
  516. }
  517. if (!player_has_interact) {
  518. infostream << "Cannot modify foreign inventory: "
  519. << "No interact privilege" << std::endl;
  520. return false;
  521. }
  522. return true;
  523. };
  524. /*
  525. Handle restrictions and special cases of the move action
  526. */
  527. if (a->getType() == IAction::Move) {
  528. IMoveAction *ma = (IMoveAction*)a.get();
  529. ma->from_inv.applyCurrentPlayer(player->getName());
  530. ma->to_inv.applyCurrentPlayer(player->getName());
  531. m_inventory_mgr->setInventoryModified(ma->from_inv);
  532. if (ma->from_inv != ma->to_inv)
  533. m_inventory_mgr->setInventoryModified(ma->to_inv);
  534. if (!check_inv_access(ma->from_inv) ||
  535. !check_inv_access(ma->to_inv))
  536. return;
  537. InventoryLocation *remote = ma->from_inv.type == InventoryLocation::PLAYER ?
  538. &ma->to_inv : &ma->from_inv;
  539. // Check for out-of-range interaction
  540. if (remote->type == InventoryLocation::NODEMETA) {
  541. v3f node_pos = intToFloat(remote->p, BS);
  542. v3f player_pos = player->getPlayerSAO()->getEyePosition();
  543. f32 d = player_pos.getDistanceFrom(node_pos);
  544. if (!checkInteractDistance(player, d, "inventory"))
  545. return;
  546. }
  547. /*
  548. Disable moving items out of craftpreview
  549. */
  550. if (ma->from_list == "craftpreview") {
  551. infostream << "Ignoring IMoveAction from "
  552. << (ma->from_inv.dump()) << ":" << ma->from_list
  553. << " to " << (ma->to_inv.dump()) << ":" << ma->to_list
  554. << " because src is " << ma->from_list << std::endl;
  555. return;
  556. }
  557. /*
  558. Disable moving items into craftresult and craftpreview
  559. */
  560. if (ma->to_list == "craftpreview" || ma->to_list == "craftresult") {
  561. infostream << "Ignoring IMoveAction from "
  562. << (ma->from_inv.dump()) << ":" << ma->from_list
  563. << " to " << (ma->to_inv.dump()) << ":" << ma->to_list
  564. << " because dst is " << ma->to_list << std::endl;
  565. return;
  566. }
  567. }
  568. /*
  569. Handle restrictions and special cases of the drop action
  570. */
  571. else if (a->getType() == IAction::Drop) {
  572. IDropAction *da = (IDropAction*)a.get();
  573. da->from_inv.applyCurrentPlayer(player->getName());
  574. m_inventory_mgr->setInventoryModified(da->from_inv);
  575. /*
  576. Disable dropping items out of craftpreview
  577. */
  578. if (da->from_list == "craftpreview") {
  579. infostream << "Ignoring IDropAction from "
  580. << (da->from_inv.dump()) << ":" << da->from_list
  581. << " because src is " << da->from_list << std::endl;
  582. return;
  583. }
  584. // Disallow dropping items if not allowed to interact
  585. if (!player_has_interact || !check_inv_access(da->from_inv))
  586. return;
  587. // Disallow dropping items if dead
  588. if (playersao->isDead()) {
  589. infostream << "Ignoring IDropAction from "
  590. << (da->from_inv.dump()) << ":" << da->from_list
  591. << " because player is dead." << std::endl;
  592. return;
  593. }
  594. }
  595. /*
  596. Handle restrictions and special cases of the craft action
  597. */
  598. else if (a->getType() == IAction::Craft) {
  599. ICraftAction *ca = (ICraftAction*)a.get();
  600. ca->craft_inv.applyCurrentPlayer(player->getName());
  601. m_inventory_mgr->setInventoryModified(ca->craft_inv);
  602. // Disallow crafting if not allowed to interact
  603. if (!player_has_interact) {
  604. infostream << "Cannot craft: "
  605. << "No interact privilege" << std::endl;
  606. return;
  607. }
  608. if (!check_inv_access(ca->craft_inv))
  609. return;
  610. } else {
  611. // Unknown action. Ignored.
  612. return;
  613. }
  614. // Do the action
  615. a->apply(m_inventory_mgr.get(), playersao, this);
  616. }
  617. void Server::handleCommand_ChatMessage(NetworkPacket* pkt)
  618. {
  619. /*
  620. u16 command
  621. u16 length
  622. wstring message
  623. */
  624. u16 len;
  625. *pkt >> len;
  626. std::wstring message;
  627. for (u16 i = 0; i < len; i++) {
  628. u16 tmp_wchar;
  629. *pkt >> tmp_wchar;
  630. message += (wchar_t)tmp_wchar;
  631. }
  632. session_t peer_id = pkt->getPeerId();
  633. RemotePlayer *player = m_env->getPlayer(peer_id);
  634. if (player == NULL) {
  635. errorstream <<
  636. "Server::ProcessData(): Canceling: No player for peer_id=" <<
  637. peer_id << " disconnecting peer!" << std::endl;
  638. DisconnectPeer(peer_id);
  639. return;
  640. }
  641. // Get player name of this client
  642. std::string name = player->getName();
  643. std::wstring wname = narrow_to_wide(name);
  644. std::wstring answer_to_sender = handleChat(name, wname, message, true, player);
  645. if (!answer_to_sender.empty()) {
  646. // Send the answer to sender
  647. SendChatMessage(peer_id, ChatMessage(CHATMESSAGE_TYPE_NORMAL,
  648. answer_to_sender, wname));
  649. }
  650. }
  651. void Server::handleCommand_Damage(NetworkPacket* pkt)
  652. {
  653. u16 damage;
  654. *pkt >> damage;
  655. session_t peer_id = pkt->getPeerId();
  656. RemotePlayer *player = m_env->getPlayer(peer_id);
  657. if (player == NULL) {
  658. errorstream <<
  659. "Server::ProcessData(): Canceling: No player for peer_id=" <<
  660. peer_id << " disconnecting peer!" << std::endl;
  661. DisconnectPeer(peer_id);
  662. return;
  663. }
  664. PlayerSAO *playersao = player->getPlayerSAO();
  665. if (playersao == NULL) {
  666. errorstream <<
  667. "Server::ProcessData(): Canceling: No player object for peer_id=" <<
  668. peer_id << " disconnecting peer!" << std::endl;
  669. DisconnectPeer(peer_id);
  670. return;
  671. }
  672. if (!playersao->isImmortal()) {
  673. if (playersao->isDead()) {
  674. verbosestream << "Server::ProcessData(): Info: "
  675. "Ignoring damage as player " << player->getName()
  676. << " is already dead." << std::endl;
  677. return;
  678. }
  679. actionstream << player->getName() << " damaged by "
  680. << (int)damage << " hp at " << PP(playersao->getBasePosition() / BS)
  681. << std::endl;
  682. PlayerHPChangeReason reason(PlayerHPChangeReason::FALL);
  683. playersao->setHP((s32)playersao->getHP() - (s32)damage, reason);
  684. SendPlayerHPOrDie(playersao, reason);
  685. }
  686. }
  687. void Server::handleCommand_PlayerItem(NetworkPacket* pkt)
  688. {
  689. if (pkt->getSize() < 2)
  690. return;
  691. session_t peer_id = pkt->getPeerId();
  692. RemotePlayer *player = m_env->getPlayer(peer_id);
  693. if (player == NULL) {
  694. errorstream <<
  695. "Server::ProcessData(): Canceling: No player for peer_id=" <<
  696. peer_id << " disconnecting peer!" << std::endl;
  697. DisconnectPeer(peer_id);
  698. return;
  699. }
  700. PlayerSAO *playersao = player->getPlayerSAO();
  701. if (playersao == NULL) {
  702. errorstream <<
  703. "Server::ProcessData(): Canceling: No player object for peer_id=" <<
  704. peer_id << " disconnecting peer!" << std::endl;
  705. DisconnectPeer(peer_id);
  706. return;
  707. }
  708. u16 item;
  709. *pkt >> item;
  710. if (item >= player->getHotbarItemcount()) {
  711. actionstream << "Player: " << player->getName()
  712. << " tried to access item=" << item
  713. << " out of hotbar_itemcount="
  714. << player->getHotbarItemcount()
  715. << "; ignoring." << std::endl;
  716. return;
  717. }
  718. playersao->getPlayer()->setWieldIndex(item);
  719. }
  720. void Server::handleCommand_Respawn(NetworkPacket* pkt)
  721. {
  722. session_t peer_id = pkt->getPeerId();
  723. RemotePlayer *player = m_env->getPlayer(peer_id);
  724. if (player == NULL) {
  725. errorstream <<
  726. "Server::ProcessData(): Canceling: No player for peer_id=" <<
  727. peer_id << " disconnecting peer!" << std::endl;
  728. DisconnectPeer(peer_id);
  729. return;
  730. }
  731. PlayerSAO *playersao = player->getPlayerSAO();
  732. assert(playersao);
  733. if (!playersao->isDead())
  734. return;
  735. RespawnPlayer(peer_id);
  736. actionstream << player->getName() << " respawns at "
  737. << PP(playersao->getBasePosition() / BS) << std::endl;
  738. // ActiveObject is added to environment in AsyncRunStep after
  739. // the previous addition has been successfully removed
  740. }
  741. bool Server::checkInteractDistance(RemotePlayer *player, const f32 d, const std::string &what)
  742. {
  743. ItemStack selected_item, hand_item;
  744. player->getWieldedItem(&selected_item, &hand_item);
  745. f32 max_d = BS * getToolRange(selected_item.getDefinition(m_itemdef),
  746. hand_item.getDefinition(m_itemdef));
  747. // Cube diagonal * 1.5 for maximal supported node extents:
  748. // sqrt(3) * 1.5 ≅ 2.6
  749. if (d > max_d + 2.6f * BS) {
  750. actionstream << "Player " << player->getName()
  751. << " tried to access " << what
  752. << " from too far: "
  753. << "d=" << d << ", max_d=" << max_d
  754. << "; ignoring." << std::endl;
  755. // Call callbacks
  756. m_script->on_cheat(player->getPlayerSAO(), "interacted_too_far");
  757. return false;
  758. }
  759. return true;
  760. }
  761. void Server::handleCommand_Interact(NetworkPacket *pkt)
  762. {
  763. /*
  764. [0] u16 command
  765. [2] u8 action
  766. [3] u16 item
  767. [5] u32 length of the next item (plen)
  768. [9] serialized PointedThing
  769. [9 + plen] player position information
  770. */
  771. InteractAction action;
  772. u16 item_i;
  773. *pkt >> (u8 &)action;
  774. *pkt >> item_i;
  775. std::istringstream tmp_is(pkt->readLongString(), std::ios::binary);
  776. PointedThing pointed;
  777. pointed.deSerialize(tmp_is);
  778. verbosestream << "TOSERVER_INTERACT: action=" << (int)action << ", item="
  779. << item_i << ", pointed=" << pointed.dump() << std::endl;
  780. session_t peer_id = pkt->getPeerId();
  781. RemotePlayer *player = m_env->getPlayer(peer_id);
  782. if (player == NULL) {
  783. errorstream <<
  784. "Server::ProcessData(): Canceling: No player for peer_id=" <<
  785. peer_id << " disconnecting peer!" << std::endl;
  786. DisconnectPeer(peer_id);
  787. return;
  788. }
  789. PlayerSAO *playersao = player->getPlayerSAO();
  790. if (playersao == NULL) {
  791. errorstream <<
  792. "Server::ProcessData(): Canceling: No player object for peer_id=" <<
  793. peer_id << " disconnecting peer!" << std::endl;
  794. DisconnectPeer(peer_id);
  795. return;
  796. }
  797. if (playersao->isDead()) {
  798. actionstream << "Server: " << player->getName()
  799. << " tried to interact while dead; ignoring." << std::endl;
  800. if (pointed.type == POINTEDTHING_NODE) {
  801. // Re-send block to revert change on client-side
  802. RemoteClient *client = getClient(peer_id);
  803. v3s16 blockpos = getNodeBlockPos(pointed.node_undersurface);
  804. client->SetBlockNotSent(blockpos);
  805. }
  806. // Call callbacks
  807. m_script->on_cheat(playersao, "interacted_while_dead");
  808. return;
  809. }
  810. process_PlayerPos(player, playersao, pkt);
  811. v3f player_pos = playersao->getLastGoodPosition();
  812. // Update wielded item
  813. if (item_i >= player->getHotbarItemcount()) {
  814. actionstream << "Player: " << player->getName()
  815. << " tried to access item=" << item_i
  816. << " out of hotbar_itemcount="
  817. << player->getHotbarItemcount()
  818. << "; ignoring." << std::endl;
  819. return;
  820. }
  821. playersao->getPlayer()->setWieldIndex(item_i);
  822. // Get pointed to object (NULL if not POINTEDTYPE_OBJECT)
  823. ServerActiveObject *pointed_object = NULL;
  824. if (pointed.type == POINTEDTHING_OBJECT) {
  825. pointed_object = m_env->getActiveObject(pointed.object_id);
  826. if (pointed_object == NULL) {
  827. verbosestream << "TOSERVER_INTERACT: "
  828. "pointed object is NULL" << std::endl;
  829. return;
  830. }
  831. }
  832. /*
  833. Make sure the player is allowed to do it
  834. */
  835. if (!checkPriv(player->getName(), "interact")) {
  836. actionstream << player->getName() << " attempted to interact with " <<
  837. pointed.dump() << " without 'interact' privilege" << std::endl;
  838. if (pointed.type != POINTEDTHING_NODE)
  839. return;
  840. // Re-send block to revert change on client-side
  841. RemoteClient *client = getClient(peer_id);
  842. // Digging completed -> under
  843. if (action == INTERACT_DIGGING_COMPLETED) {
  844. v3s16 blockpos = getNodeBlockPos(pointed.node_undersurface);
  845. client->SetBlockNotSent(blockpos);
  846. }
  847. // Placement -> above
  848. else if (action == INTERACT_PLACE) {
  849. v3s16 blockpos = getNodeBlockPos(pointed.node_abovesurface);
  850. client->SetBlockNotSent(blockpos);
  851. }
  852. return;
  853. }
  854. /*
  855. Check that target is reasonably close
  856. */
  857. static thread_local const bool enable_anticheat =
  858. !g_settings->getBool("disable_anticheat");
  859. if ((action == INTERACT_START_DIGGING || action == INTERACT_DIGGING_COMPLETED ||
  860. action == INTERACT_PLACE || action == INTERACT_USE) &&
  861. enable_anticheat && !isSingleplayer()) {
  862. v3f target_pos = player_pos;
  863. if (pointed.type == POINTEDTHING_NODE) {
  864. target_pos = intToFloat(pointed.node_undersurface, BS);
  865. } else if (pointed.type == POINTEDTHING_OBJECT) {
  866. target_pos = pointed_object->getBasePosition();
  867. }
  868. float d = playersao->getEyePosition().getDistanceFrom(target_pos);
  869. if (!checkInteractDistance(player, d, pointed.dump())) {
  870. if (pointed.type == POINTEDTHING_NODE) {
  871. // Re-send block to revert change on client-side
  872. RemoteClient *client = getClient(peer_id);
  873. v3s16 blockpos = getNodeBlockPos(pointed.node_undersurface);
  874. client->SetBlockNotSent(blockpos);
  875. }
  876. return;
  877. }
  878. }
  879. /*
  880. If something goes wrong, this player is to blame
  881. */
  882. RollbackScopeActor rollback_scope(m_rollback,
  883. std::string("player:")+player->getName());
  884. switch (action) {
  885. // Start digging or punch object
  886. case INTERACT_START_DIGGING: {
  887. if (pointed.type == POINTEDTHING_NODE) {
  888. MapNode n(CONTENT_IGNORE);
  889. bool pos_ok;
  890. v3s16 p_under = pointed.node_undersurface;
  891. n = m_env->getMap().getNode(p_under, &pos_ok);
  892. if (!pos_ok) {
  893. infostream << "Server: Not punching: Node not found. "
  894. "Adding block to emerge queue." << std::endl;
  895. m_emerge->enqueueBlockEmerge(peer_id,
  896. getNodeBlockPos(pointed.node_abovesurface), false);
  897. }
  898. if (n.getContent() != CONTENT_IGNORE)
  899. m_script->node_on_punch(p_under, n, playersao, pointed);
  900. // Cheat prevention
  901. playersao->noCheatDigStart(p_under);
  902. return;
  903. }
  904. // Skip if the object can't be interacted with anymore
  905. if (pointed.type != POINTEDTHING_OBJECT || pointed_object->isGone())
  906. return;
  907. ItemStack selected_item, hand_item;
  908. ItemStack tool_item = playersao->getWieldedItem(&selected_item, &hand_item);
  909. ToolCapabilities toolcap =
  910. tool_item.getToolCapabilities(m_itemdef);
  911. v3f dir = (pointed_object->getBasePosition() -
  912. (playersao->getBasePosition() + playersao->getEyeOffset())
  913. ).normalize();
  914. float time_from_last_punch =
  915. playersao->resetTimeFromLastPunch();
  916. u16 src_original_hp = pointed_object->getHP();
  917. u16 dst_origin_hp = playersao->getHP();
  918. u16 wear = pointed_object->punch(dir, &toolcap, playersao,
  919. time_from_last_punch);
  920. // Callback may have changed item, so get it again
  921. playersao->getWieldedItem(&selected_item);
  922. bool changed = selected_item.addWear(wear, m_itemdef);
  923. if (changed)
  924. playersao->setWieldedItem(selected_item);
  925. // If the object is a player and its HP changed
  926. if (src_original_hp != pointed_object->getHP() &&
  927. pointed_object->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
  928. SendPlayerHPOrDie((PlayerSAO *)pointed_object,
  929. PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, playersao));
  930. }
  931. // If the puncher is a player and its HP changed
  932. if (dst_origin_hp != playersao->getHP())
  933. SendPlayerHPOrDie(playersao,
  934. PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, pointed_object));
  935. return;
  936. } // action == INTERACT_START_DIGGING
  937. case INTERACT_STOP_DIGGING:
  938. // Nothing to do
  939. return;
  940. case INTERACT_DIGGING_COMPLETED: {
  941. // Only digging of nodes
  942. if (pointed.type != POINTEDTHING_NODE)
  943. return;
  944. bool pos_ok;
  945. v3s16 p_under = pointed.node_undersurface;
  946. MapNode n = m_env->getMap().getNode(p_under, &pos_ok);
  947. if (!pos_ok) {
  948. infostream << "Server: Not finishing digging: Node not found. "
  949. "Adding block to emerge queue." << std::endl;
  950. m_emerge->enqueueBlockEmerge(peer_id,
  951. getNodeBlockPos(pointed.node_abovesurface), false);
  952. }
  953. /* Cheat prevention */
  954. bool is_valid_dig = true;
  955. if (enable_anticheat && !isSingleplayer()) {
  956. v3s16 nocheat_p = playersao->getNoCheatDigPos();
  957. float nocheat_t = playersao->getNoCheatDigTime();
  958. playersao->noCheatDigEnd();
  959. // If player didn't start digging this, ignore dig
  960. if (nocheat_p != p_under) {
  961. infostream << "Server: " << player->getName()
  962. << " started digging "
  963. << PP(nocheat_p) << " and completed digging "
  964. << PP(p_under) << "; not digging." << std::endl;
  965. is_valid_dig = false;
  966. // Call callbacks
  967. m_script->on_cheat(playersao, "finished_unknown_dig");
  968. }
  969. // Get player's wielded item
  970. // See also: Game::handleDigging
  971. ItemStack selected_item, hand_item;
  972. playersao->getPlayer()->getWieldedItem(&selected_item, &hand_item);
  973. // Get diggability and expected digging time
  974. DigParams params = getDigParams(m_nodedef->get(n).groups,
  975. &selected_item.getToolCapabilities(m_itemdef));
  976. // If can't dig, try hand
  977. if (!params.diggable) {
  978. params = getDigParams(m_nodedef->get(n).groups,
  979. &hand_item.getToolCapabilities(m_itemdef));
  980. }
  981. // If can't dig, ignore dig
  982. if (!params.diggable) {
  983. infostream << "Server: " << player->getName()
  984. << " completed digging " << PP(p_under)
  985. << ", which is not diggable with tool; not digging."
  986. << std::endl;
  987. is_valid_dig = false;
  988. // Call callbacks
  989. m_script->on_cheat(playersao, "dug_unbreakable");
  990. }
  991. // Check digging time
  992. // If already invalidated, we don't have to
  993. if (!is_valid_dig) {
  994. // Well not our problem then
  995. }
  996. // Clean and long dig
  997. else if (params.time > 2.0 && nocheat_t * 1.2 > params.time) {
  998. // All is good, but grab time from pool; don't care if
  999. // it's actually available
  1000. playersao->getDigPool().grab(params.time);
  1001. }
  1002. // Short or laggy dig
  1003. // Try getting the time from pool
  1004. else if (playersao->getDigPool().grab(params.time)) {
  1005. // All is good
  1006. }
  1007. // Dig not possible
  1008. else {
  1009. infostream << "Server: " << player->getName()
  1010. << " completed digging " << PP(p_under)
  1011. << "too fast; not digging." << std::endl;
  1012. is_valid_dig = false;
  1013. // Call callbacks
  1014. m_script->on_cheat(playersao, "dug_too_fast");
  1015. }
  1016. }
  1017. /* Actually dig node */
  1018. if (is_valid_dig && n.getContent() != CONTENT_IGNORE)
  1019. m_script->node_on_dig(p_under, n, playersao);
  1020. v3s16 blockpos = getNodeBlockPos(p_under);
  1021. RemoteClient *client = getClient(peer_id);
  1022. // Send unusual result (that is, node not being removed)
  1023. if (m_env->getMap().getNode(p_under).getContent() != CONTENT_AIR)
  1024. // Re-send block to revert change on client-side
  1025. client->SetBlockNotSent(blockpos);
  1026. else
  1027. client->ResendBlockIfOnWire(blockpos);
  1028. return;
  1029. } // action == INTERACT_DIGGING_COMPLETED
  1030. // Place block or right-click object
  1031. case INTERACT_PLACE: {
  1032. ItemStack selected_item;
  1033. playersao->getWieldedItem(&selected_item, nullptr);
  1034. // Reset build time counter
  1035. if (pointed.type == POINTEDTHING_NODE &&
  1036. selected_item.getDefinition(m_itemdef).type == ITEM_NODE)
  1037. getClient(peer_id)->m_time_from_building = 0.0;
  1038. if (pointed.type == POINTEDTHING_OBJECT) {
  1039. // Right click object
  1040. // Skip if object can't be interacted with anymore
  1041. if (pointed_object->isGone())
  1042. return;
  1043. actionstream << player->getName() << " right-clicks object "
  1044. << pointed.object_id << ": "
  1045. << pointed_object->getDescription() << std::endl;
  1046. // Do stuff
  1047. if (m_script->item_OnSecondaryUse(
  1048. selected_item, playersao, pointed)) {
  1049. if (playersao->setWieldedItem(selected_item)) {
  1050. SendInventory(playersao, true);
  1051. }
  1052. }
  1053. pointed_object->rightClick(playersao);
  1054. } else if (m_script->item_OnPlace(selected_item, playersao, pointed)) {
  1055. // Placement was handled in lua
  1056. // Apply returned ItemStack
  1057. if (playersao->setWieldedItem(selected_item))
  1058. SendInventory(playersao, true);
  1059. }
  1060. if (pointed.type != POINTEDTHING_NODE)
  1061. return;
  1062. // If item has node placement prediction, always send the
  1063. // blocks to make sure the client knows what exactly happened
  1064. RemoteClient *client = getClient(peer_id);
  1065. v3s16 blockpos = getNodeBlockPos(pointed.node_abovesurface);
  1066. v3s16 blockpos2 = getNodeBlockPos(pointed.node_undersurface);
  1067. if (!selected_item.getDefinition(m_itemdef
  1068. ).node_placement_prediction.empty()) {
  1069. client->SetBlockNotSent(blockpos);
  1070. if (blockpos2 != blockpos)
  1071. client->SetBlockNotSent(blockpos2);
  1072. } else {
  1073. client->ResendBlockIfOnWire(blockpos);
  1074. if (blockpos2 != blockpos)
  1075. client->ResendBlockIfOnWire(blockpos2);
  1076. }
  1077. return;
  1078. } // action == INTERACT_PLACE
  1079. case INTERACT_USE: {
  1080. ItemStack selected_item;
  1081. playersao->getWieldedItem(&selected_item, nullptr);
  1082. actionstream << player->getName() << " uses " << selected_item.name
  1083. << ", pointing at " << pointed.dump() << std::endl;
  1084. if (m_script->item_OnUse(selected_item, playersao, pointed)) {
  1085. // Apply returned ItemStack
  1086. if (playersao->setWieldedItem(selected_item))
  1087. SendInventory(playersao, true);
  1088. }
  1089. return;
  1090. }
  1091. // Rightclick air
  1092. case INTERACT_ACTIVATE: {
  1093. ItemStack selected_item;
  1094. playersao->getWieldedItem(&selected_item, nullptr);
  1095. actionstream << player->getName() << " activates "
  1096. << selected_item.name << std::endl;
  1097. pointed.type = POINTEDTHING_NOTHING; // can only ever be NOTHING
  1098. if (m_script->item_OnSecondaryUse(selected_item, playersao, pointed)) {
  1099. if (playersao->setWieldedItem(selected_item))
  1100. SendInventory(playersao, true);
  1101. }
  1102. return;
  1103. }
  1104. default:
  1105. warningstream << "Server: Invalid action " << action << std::endl;
  1106. }
  1107. }
  1108. void Server::handleCommand_RemovedSounds(NetworkPacket* pkt)
  1109. {
  1110. u16 num;
  1111. *pkt >> num;
  1112. for (u16 k = 0; k < num; k++) {
  1113. s32 id;
  1114. *pkt >> id;
  1115. std::unordered_map<s32, ServerPlayingSound>::iterator i =
  1116. m_playing_sounds.find(id);
  1117. if (i == m_playing_sounds.end())
  1118. continue;
  1119. ServerPlayingSound &psound = i->second;
  1120. psound.clients.erase(pkt->getPeerId());
  1121. if (psound.clients.empty())
  1122. m_playing_sounds.erase(i++);
  1123. }
  1124. }
  1125. void Server::handleCommand_NodeMetaFields(NetworkPacket* pkt)
  1126. {
  1127. v3s16 p;
  1128. std::string formname;
  1129. u16 num;
  1130. *pkt >> p >> formname >> num;
  1131. StringMap fields;
  1132. for (u16 k = 0; k < num; k++) {
  1133. std::string fieldname;
  1134. *pkt >> fieldname;
  1135. fields[fieldname] = pkt->readLongString();
  1136. }
  1137. session_t peer_id = pkt->getPeerId();
  1138. RemotePlayer *player = m_env->getPlayer(peer_id);
  1139. if (player == NULL) {
  1140. errorstream <<
  1141. "Server::ProcessData(): Canceling: No player for peer_id=" <<
  1142. peer_id << " disconnecting peer!" << std::endl;
  1143. DisconnectPeer(peer_id);
  1144. return;
  1145. }
  1146. PlayerSAO *playersao = player->getPlayerSAO();
  1147. if (playersao == NULL) {
  1148. errorstream <<
  1149. "Server::ProcessData(): Canceling: No player object for peer_id=" <<
  1150. peer_id << " disconnecting peer!" << std::endl;
  1151. DisconnectPeer(peer_id);
  1152. return;
  1153. }
  1154. // If something goes wrong, this player is to blame
  1155. RollbackScopeActor rollback_scope(m_rollback,
  1156. std::string("player:")+player->getName());
  1157. // Check the target node for rollback data; leave others unnoticed
  1158. RollbackNode rn_old(&m_env->getMap(), p, this);
  1159. m_script->node_on_receive_fields(p, formname, fields, playersao);
  1160. // Report rollback data
  1161. RollbackNode rn_new(&m_env->getMap(), p, this);
  1162. if (rollback() && rn_new != rn_old) {
  1163. RollbackAction action;
  1164. action.setSetNode(p, rn_old, rn_new);
  1165. rollback()->reportAction(action);
  1166. }
  1167. }
  1168. void Server::handleCommand_InventoryFields(NetworkPacket* pkt)
  1169. {
  1170. std::string client_formspec_name;
  1171. u16 num;
  1172. *pkt >> client_formspec_name >> num;
  1173. StringMap fields;
  1174. for (u16 k = 0; k < num; k++) {
  1175. std::string fieldname;
  1176. *pkt >> fieldname;
  1177. fields[fieldname] = pkt->readLongString();
  1178. }
  1179. session_t peer_id = pkt->getPeerId();
  1180. RemotePlayer *player = m_env->getPlayer(peer_id);
  1181. if (player == NULL) {
  1182. errorstream <<
  1183. "Server::ProcessData(): Canceling: No player for peer_id=" <<
  1184. peer_id << " disconnecting peer!" << std::endl;
  1185. DisconnectPeer(peer_id);
  1186. return;
  1187. }
  1188. PlayerSAO *playersao = player->getPlayerSAO();
  1189. if (playersao == NULL) {
  1190. errorstream <<
  1191. "Server::ProcessData(): Canceling: No player object for peer_id=" <<
  1192. peer_id << " disconnecting peer!" << std::endl;
  1193. DisconnectPeer(peer_id);
  1194. return;
  1195. }
  1196. if (client_formspec_name.empty()) { // pass through inventory submits
  1197. m_script->on_playerReceiveFields(playersao, client_formspec_name, fields);
  1198. return;
  1199. }
  1200. // verify that we displayed the formspec to the user
  1201. const auto peer_state_iterator = m_formspec_state_data.find(peer_id);
  1202. if (peer_state_iterator != m_formspec_state_data.end()) {
  1203. const std::string &server_formspec_name = peer_state_iterator->second;
  1204. if (client_formspec_name == server_formspec_name) {
  1205. auto it = fields.find("quit");
  1206. if (it != fields.end() && it->second == "true")
  1207. m_formspec_state_data.erase(peer_state_iterator);
  1208. m_script->on_playerReceiveFields(playersao, client_formspec_name, fields);
  1209. return;
  1210. }
  1211. actionstream << "'" << player->getName()
  1212. << "' submitted formspec ('" << client_formspec_name
  1213. << "') but the name of the formspec doesn't match the"
  1214. " expected name ('" << server_formspec_name << "')";
  1215. } else {
  1216. actionstream << "'" << player->getName()
  1217. << "' submitted formspec ('" << client_formspec_name
  1218. << "') but server hasn't sent formspec to client";
  1219. }
  1220. actionstream << ", possible exploitation attempt" << std::endl;
  1221. }
  1222. void Server::handleCommand_FirstSrp(NetworkPacket* pkt)
  1223. {
  1224. session_t peer_id = pkt->getPeerId();
  1225. RemoteClient *client = getClient(peer_id, CS_Invalid);
  1226. ClientState cstate = client->getState();
  1227. std::string playername = client->getName();
  1228. std::string salt;
  1229. std::string verification_key;
  1230. std::string addr_s = getPeerAddress(peer_id).serializeString();
  1231. u8 is_empty;
  1232. *pkt >> salt >> verification_key >> is_empty;
  1233. verbosestream << "Server: Got TOSERVER_FIRST_SRP from " << addr_s
  1234. << ", with is_empty=" << (is_empty == 1) << std::endl;
  1235. // Either this packet is sent because the user is new or to change the password
  1236. if (cstate == CS_HelloSent) {
  1237. if (!client->isMechAllowed(AUTH_MECHANISM_FIRST_SRP)) {
  1238. actionstream << "Server: Client from " << addr_s
  1239. << " tried to set password without being "
  1240. << "authenticated, or the username being new." << std::endl;
  1241. DenyAccess(peer_id, SERVER_ACCESSDENIED_UNEXPECTED_DATA);
  1242. return;
  1243. }
  1244. if (!isSingleplayer() &&
  1245. g_settings->getBool("disallow_empty_password") &&
  1246. is_empty == 1) {
  1247. actionstream << "Server: " << playername
  1248. << " supplied empty password from " << addr_s << std::endl;
  1249. DenyAccess(peer_id, SERVER_ACCESSDENIED_EMPTY_PASSWORD);
  1250. return;
  1251. }
  1252. std::string initial_ver_key;
  1253. initial_ver_key = encode_srp_verifier(verification_key, salt);
  1254. m_script->createAuth(playername, initial_ver_key);
  1255. m_script->on_authplayer(playername, addr_s, true);
  1256. acceptAuth(peer_id, false);
  1257. } else {
  1258. if (cstate < CS_SudoMode) {
  1259. infostream << "Server::ProcessData(): Ignoring TOSERVER_FIRST_SRP from "
  1260. << addr_s << ": " << "Client has wrong state " << cstate << "."
  1261. << std::endl;
  1262. return;
  1263. }
  1264. m_clients.event(peer_id, CSE_SudoLeave);
  1265. std::string pw_db_field = encode_srp_verifier(verification_key, salt);
  1266. bool success = m_script->setPassword(playername, pw_db_field);
  1267. if (success) {
  1268. actionstream << playername << " changes password" << std::endl;
  1269. SendChatMessage(peer_id, ChatMessage(CHATMESSAGE_TYPE_SYSTEM,
  1270. L"Password change successful."));
  1271. } else {
  1272. actionstream << playername <<
  1273. " tries to change password but it fails" << std::endl;
  1274. SendChatMessage(peer_id, ChatMessage(CHATMESSAGE_TYPE_SYSTEM,
  1275. L"Password change failed or unavailable."));
  1276. }
  1277. }
  1278. }
  1279. void Server::handleCommand_SrpBytesA(NetworkPacket* pkt)
  1280. {
  1281. session_t peer_id = pkt->getPeerId();
  1282. RemoteClient *client = getClient(peer_id, CS_Invalid);
  1283. ClientState cstate = client->getState();
  1284. bool wantSudo = (cstate == CS_Active);
  1285. if (!((cstate == CS_HelloSent) || (cstate == CS_Active))) {
  1286. actionstream << "Server: got SRP _A packet in wrong state " << cstate <<
  1287. " from " << getPeerAddress(peer_id).serializeString() <<
  1288. ". Ignoring." << std::endl;
  1289. return;
  1290. }
  1291. if (client->chosen_mech != AUTH_MECHANISM_NONE) {
  1292. actionstream << "Server: got SRP _A packet, while auth is already "
  1293. "going on with mech " << client->chosen_mech << " from " <<
  1294. getPeerAddress(peer_id).serializeString() <<
  1295. " (wantSudo=" << wantSudo << "). Ignoring." << std::endl;
  1296. if (wantSudo) {
  1297. DenySudoAccess(peer_id);
  1298. return;
  1299. }
  1300. DenyAccess(peer_id, SERVER_ACCESSDENIED_UNEXPECTED_DATA);
  1301. return;
  1302. }
  1303. std::string bytes_A;
  1304. u8 based_on;
  1305. *pkt >> bytes_A >> based_on;
  1306. infostream << "Server: TOSERVER_SRP_BYTES_A received with "
  1307. << "based_on=" << int(based_on) << " and len_A="
  1308. << bytes_A.length() << "." << std::endl;
  1309. AuthMechanism chosen = (based_on == 0) ?
  1310. AUTH_MECHANISM_LEGACY_PASSWORD : AUTH_MECHANISM_SRP;
  1311. if (wantSudo) {
  1312. if (!client->isSudoMechAllowed(chosen)) {
  1313. actionstream << "Server: Player \"" << client->getName() <<
  1314. "\" at " << getPeerAddress(peer_id).serializeString() <<
  1315. " tried to change password using unallowed mech " << chosen <<
  1316. "." << std::endl;
  1317. DenySudoAccess(peer_id);
  1318. return;
  1319. }
  1320. } else {
  1321. if (!client->isMechAllowed(chosen)) {
  1322. actionstream << "Server: Client tried to authenticate from " <<
  1323. getPeerAddress(peer_id).serializeString() <<
  1324. " using unallowed mech " << chosen << "." << std::endl;
  1325. DenyAccess(peer_id, SERVER_ACCESSDENIED_UNEXPECTED_DATA);
  1326. return;
  1327. }
  1328. }
  1329. client->chosen_mech = chosen;
  1330. std::string salt;
  1331. std::string verifier;
  1332. if (based_on == 0) {
  1333. generate_srp_verifier_and_salt(client->getName(), client->enc_pwd,
  1334. &verifier, &salt);
  1335. } else if (!decode_srp_verifier_and_salt(client->enc_pwd, &verifier, &salt)) {
  1336. // Non-base64 errors should have been catched in the init handler
  1337. actionstream << "Server: User " << client->getName() <<
  1338. " tried to log in, but srp verifier field was invalid (most likely "
  1339. "invalid base64)." << std::endl;
  1340. DenyAccess(peer_id, SERVER_ACCESSDENIED_SERVER_FAIL);
  1341. return;
  1342. }
  1343. char *bytes_B = 0;
  1344. size_t len_B = 0;
  1345. client->auth_data = srp_verifier_new(SRP_SHA256, SRP_NG_2048,
  1346. client->getName().c_str(),
  1347. (const unsigned char *) salt.c_str(), salt.size(),
  1348. (const unsigned char *) verifier.c_str(), verifier.size(),
  1349. (const unsigned char *) bytes_A.c_str(), bytes_A.size(),
  1350. NULL, 0,
  1351. (unsigned char **) &bytes_B, &len_B, NULL, NULL);
  1352. if (!bytes_B) {
  1353. actionstream << "Server: User " << client->getName()
  1354. << " tried to log in, SRP-6a safety check violated in _A handler."
  1355. << std::endl;
  1356. if (wantSudo) {
  1357. DenySudoAccess(peer_id);
  1358. return;
  1359. }
  1360. DenyAccess(peer_id, SERVER_ACCESSDENIED_UNEXPECTED_DATA);
  1361. return;
  1362. }
  1363. NetworkPacket resp_pkt(TOCLIENT_SRP_BYTES_S_B, 0, peer_id);
  1364. resp_pkt << salt << std::string(bytes_B, len_B);
  1365. Send(&resp_pkt);
  1366. }
  1367. void Server::handleCommand_SrpBytesM(NetworkPacket* pkt)
  1368. {
  1369. session_t peer_id = pkt->getPeerId();
  1370. RemoteClient *client = getClient(peer_id, CS_Invalid);
  1371. ClientState cstate = client->getState();
  1372. std::string addr_s = getPeerAddress(pkt->getPeerId()).serializeString();
  1373. std::string playername = client->getName();
  1374. bool wantSudo = (cstate == CS_Active);
  1375. verbosestream << "Server: Received TOSERVER_SRP_BYTES_M." << std::endl;
  1376. if (!((cstate == CS_HelloSent) || (cstate == CS_Active))) {
  1377. warningstream << "Server: got SRP_M packet in wrong state "
  1378. << cstate << " from " << addr_s << ". Ignoring." << std::endl;
  1379. return;
  1380. }
  1381. if (client->chosen_mech != AUTH_MECHANISM_SRP &&
  1382. client->chosen_mech != AUTH_MECHANISM_LEGACY_PASSWORD) {
  1383. warningstream << "Server: got SRP_M packet, while auth "
  1384. "is going on with mech " << client->chosen_mech << " from "
  1385. << addr_s << " (wantSudo=" << wantSudo << "). Denying." << std::endl;
  1386. if (wantSudo) {
  1387. DenySudoAccess(peer_id);
  1388. return;
  1389. }
  1390. DenyAccess(peer_id, SERVER_ACCESSDENIED_UNEXPECTED_DATA);
  1391. return;
  1392. }
  1393. std::string bytes_M;
  1394. *pkt >> bytes_M;
  1395. if (srp_verifier_get_session_key_length((SRPVerifier *) client->auth_data)
  1396. != bytes_M.size()) {
  1397. actionstream << "Server: User " << playername << " at " << addr_s
  1398. << " sent bytes_M with invalid length " << bytes_M.size() << std::endl;
  1399. DenyAccess(peer_id, SERVER_ACCESSDENIED_UNEXPECTED_DATA);
  1400. return;
  1401. }
  1402. unsigned char *bytes_HAMK = 0;
  1403. srp_verifier_verify_session((SRPVerifier *) client->auth_data,
  1404. (unsigned char *)bytes_M.c_str(), &bytes_HAMK);
  1405. if (!bytes_HAMK) {
  1406. if (wantSudo) {
  1407. actionstream << "Server: User " << playername << " at " << addr_s
  1408. << " tried to change their password, but supplied wrong"
  1409. << " (SRP) password for authentication." << std::endl;
  1410. DenySudoAccess(peer_id);
  1411. return;
  1412. }
  1413. actionstream << "Server: User " << playername << " at " << addr_s
  1414. << " supplied wrong password (auth mechanism: SRP)." << std::endl;
  1415. m_script->on_authplayer(playername, addr_s, false);
  1416. DenyAccess(peer_id, SERVER_ACCESSDENIED_WRONG_PASSWORD);
  1417. return;
  1418. }
  1419. if (client->create_player_on_auth_success) {
  1420. m_script->createAuth(playername, client->enc_pwd);
  1421. std::string checkpwd; // not used, but needed for passing something
  1422. if (!m_script->getAuth(playername, &checkpwd, NULL)) {
  1423. errorstream << "Server: " << playername <<
  1424. " cannot be authenticated (auth handler does not work?)" <<
  1425. std::endl;
  1426. DenyAccess(peer_id, SERVER_ACCESSDENIED_SERVER_FAIL);
  1427. return;
  1428. }
  1429. client->create_player_on_auth_success = false;
  1430. }
  1431. m_script->on_authplayer(playername, addr_s, true);
  1432. acceptAuth(peer_id, wantSudo);
  1433. }
  1434. /*
  1435. * Mod channels
  1436. */
  1437. void Server::handleCommand_ModChannelJoin(NetworkPacket *pkt)
  1438. {
  1439. std::string channel_name;
  1440. *pkt >> channel_name;
  1441. session_t peer_id = pkt->getPeerId();
  1442. NetworkPacket resp_pkt(TOCLIENT_MODCHANNEL_SIGNAL,
  1443. 1 + 2 + channel_name.size(), peer_id);
  1444. // Send signal to client to notify join succeed or not
  1445. if (g_settings->getBool("enable_mod_channels") &&
  1446. m_modchannel_mgr->joinChannel(channel_name, peer_id)) {
  1447. resp_pkt << (u8) MODCHANNEL_SIGNAL_JOIN_OK;
  1448. infostream << "Peer " << peer_id << " joined channel " <<
  1449. channel_name << std::endl;
  1450. }
  1451. else {
  1452. resp_pkt << (u8)MODCHANNEL_SIGNAL_JOIN_FAILURE;
  1453. infostream << "Peer " << peer_id << " tried to join channel " <<
  1454. channel_name << ", but was already registered." << std::endl;
  1455. }
  1456. resp_pkt << channel_name;
  1457. Send(&resp_pkt);
  1458. }
  1459. void Server::handleCommand_ModChannelLeave(NetworkPacket *pkt)
  1460. {
  1461. std::string channel_name;
  1462. *pkt >> channel_name;
  1463. session_t peer_id = pkt->getPeerId();
  1464. NetworkPacket resp_pkt(TOCLIENT_MODCHANNEL_SIGNAL,
  1465. 1 + 2 + channel_name.size(), peer_id);
  1466. // Send signal to client to notify join succeed or not
  1467. if (g_settings->getBool("enable_mod_channels") &&
  1468. m_modchannel_mgr->leaveChannel(channel_name, peer_id)) {
  1469. resp_pkt << (u8)MODCHANNEL_SIGNAL_LEAVE_OK;
  1470. infostream << "Peer " << peer_id << " left channel " << channel_name <<
  1471. std::endl;
  1472. } else {
  1473. resp_pkt << (u8) MODCHANNEL_SIGNAL_LEAVE_FAILURE;
  1474. infostream << "Peer " << peer_id << " left channel " << channel_name <<
  1475. ", but was not registered." << std::endl;
  1476. }
  1477. resp_pkt << channel_name;
  1478. Send(&resp_pkt);
  1479. }
  1480. void Server::handleCommand_ModChannelMsg(NetworkPacket *pkt)
  1481. {
  1482. std::string channel_name, channel_msg;
  1483. *pkt >> channel_name >> channel_msg;
  1484. session_t peer_id = pkt->getPeerId();
  1485. verbosestream << "Mod channel message received from peer " << peer_id <<
  1486. " on channel " << channel_name << " message: " << channel_msg <<
  1487. std::endl;
  1488. // If mod channels are not enabled, discard message
  1489. if (!g_settings->getBool("enable_mod_channels")) {
  1490. return;
  1491. }
  1492. // If channel not registered, signal it and ignore message
  1493. if (!m_modchannel_mgr->channelRegistered(channel_name)) {
  1494. NetworkPacket resp_pkt(TOCLIENT_MODCHANNEL_SIGNAL,
  1495. 1 + 2 + channel_name.size(), peer_id);
  1496. resp_pkt << (u8)MODCHANNEL_SIGNAL_CHANNEL_NOT_REGISTERED << channel_name;
  1497. Send(&resp_pkt);
  1498. return;
  1499. }
  1500. // @TODO: filter, rate limit
  1501. broadcastModChannelMessage(channel_name, channel_msg, peer_id);
  1502. }