+
+void Client::handleCommand_UpdatePlayerList(NetworkPacket* pkt)
+{
+ u8 type;
+ u16 num_players;
+ *pkt >> type >> num_players;
+ PlayerListModifer notice_type = (PlayerListModifer) type;
+
+ for (u16 i = 0; i < num_players; i++) {
+ std::string name;
+ *pkt >> name;
+ switch (notice_type) {
+ case PLAYER_LIST_INIT:
+ case PLAYER_LIST_ADD:
+ m_env.addPlayerName(name);
+ continue;
+ case PLAYER_LIST_REMOVE:
+ m_env.removePlayerName(name);
+ continue;
+ }
+ }
+}
+
+void Client::handleCommand_SrpBytesSandB(NetworkPacket* pkt)
+{
+ if (m_chosen_auth_mech != AUTH_MECHANISM_SRP &&
+ m_chosen_auth_mech != AUTH_MECHANISM_LEGACY_PASSWORD) {
+ errorstream << "Client: Received SRP S_B login message,"
+ << " but wasn't supposed to (chosen_mech="
+ << m_chosen_auth_mech << ")." << std::endl;
+ return;
+ }
+
+ char *bytes_M = 0;
+ size_t len_M = 0;
+ SRPUser *usr = (SRPUser *) m_auth_data;
+ std::string s;
+ std::string B;
+ *pkt >> s >> B;
+
+ infostream << "Client: Received TOCLIENT_SRP_BYTES_S_B." << std::endl;
+
+ srp_user_process_challenge(usr, (const unsigned char *) s.c_str(), s.size(),
+ (const unsigned char *) B.c_str(), B.size(),
+ (unsigned char **) &bytes_M, &len_M);
+
+ if ( !bytes_M ) {
+ errorstream << "Client: SRP-6a S_B safety check violation!" << std::endl;
+ return;
+ }
+
+ NetworkPacket resp_pkt(TOSERVER_SRP_BYTES_M, 0);
+ resp_pkt << std::string(bytes_M, len_M);
+ Send(&resp_pkt);
+}
+
+void Client::handleCommand_FormspecPrepend(NetworkPacket *pkt)
+{
+ LocalPlayer *player = m_env.getLocalPlayer();
+ assert(player != NULL);
+
+ // Store formspec in LocalPlayer
+ *pkt >> player->formspec_prepend;
+}
+
+void Client::handleCommand_CSMRestrictionFlags(NetworkPacket *pkt)
+{
+ *pkt >> m_csm_restriction_flags >> m_csm_restriction_noderange;
+
+ // Restrictions were received -> load mods if it's enabled
+ // Note: this should be moved after mods receptions from server instead
+ loadMods();
+}
+
+void Client::handleCommand_PlayerSpeed(NetworkPacket *pkt)
+{
+ v3f added_vel;
+
+ *pkt >> added_vel;
+
+ LocalPlayer *player = m_env.getLocalPlayer();
+ assert(player != NULL);
+ player->addVelocity(added_vel);
+}
+
+/*
+ * Mod channels
+ */
+
+void Client::handleCommand_ModChannelMsg(NetworkPacket *pkt)
+{
+ std::string channel_name, sender, channel_msg;
+ *pkt >> channel_name >> sender >> channel_msg;
+
+ verbosestream << "Mod channel message received from server " << pkt->getPeerId()
+ << " on channel " << channel_name << ". sender: `" << sender << "`, message: "
+ << channel_msg << std::endl;
+
+ if (!m_modchannel_mgr->channelRegistered(channel_name)) {
+ verbosestream << "Server sent us messages on unregistered channel "
+ << channel_name << ", ignoring." << std::endl;
+ return;
+ }
+
+ m_script->on_modchannel_message(channel_name, sender, channel_msg);
+}
+
+void Client::handleCommand_ModChannelSignal(NetworkPacket *pkt)
+{
+ u8 signal_tmp;
+ ModChannelSignal signal;
+ std::string channel;
+
+ *pkt >> signal_tmp >> channel;
+
+ signal = (ModChannelSignal)signal_tmp;
+
+ bool valid_signal = true;
+ // @TODO: send Signal to Lua API
+ switch (signal) {
+ case MODCHANNEL_SIGNAL_JOIN_OK:
+ m_modchannel_mgr->setChannelState(channel, MODCHANNEL_STATE_READ_WRITE);
+ infostream << "Server ack our mod channel join on channel `" << channel
+ << "`, joining." << std::endl;
+ break;
+ case MODCHANNEL_SIGNAL_JOIN_FAILURE:
+ // Unable to join, remove channel
+ m_modchannel_mgr->leaveChannel(channel, 0);
+ infostream << "Server refused our mod channel join on channel `" << channel
+ << "`" << std::endl;
+ break;
+ case MODCHANNEL_SIGNAL_LEAVE_OK:
+#ifndef NDEBUG
+ infostream << "Server ack our mod channel leave on channel " << channel
+ << "`, leaving." << std::endl;
+#endif
+ break;
+ case MODCHANNEL_SIGNAL_LEAVE_FAILURE:
+ infostream << "Server refused our mod channel leave on channel `" << channel
+ << "`" << std::endl;
+ break;
+ case MODCHANNEL_SIGNAL_CHANNEL_NOT_REGISTERED:
+#ifndef NDEBUG
+ // Generally unused, but ensure we don't do an implementation error
+ infostream << "Server tells us we sent a message on channel `" << channel
+ << "` but we are not registered. Message was dropped." << std::endl;
+#endif
+ break;
+ case MODCHANNEL_SIGNAL_SET_STATE: {
+ u8 state;
+ *pkt >> state;
+
+ if (state == MODCHANNEL_STATE_INIT || state >= MODCHANNEL_STATE_MAX) {
+ infostream << "Received wrong channel state " << state
+ << ", ignoring." << std::endl;
+ return;
+ }
+
+ m_modchannel_mgr->setChannelState(channel, (ModChannelState) state);
+ infostream << "Server sets mod channel `" << channel
+ << "` in read-only mode." << std::endl;
+ break;
+ }
+ default:
+#ifndef NDEBUG
+ warningstream << "Received unhandled mod channel signal ID "
+ << signal << ", ignoring." << std::endl;
+#endif
+ valid_signal = false;
+ break;
+ }
+
+ // If signal is valid, forward it to client side mods
+ if (valid_signal)
+ m_script->on_modchannel_signal(channel, signal);
+}