From 37e9cafbf760469f56bded4ddaff7d09465033e4 Mon Sep 17 00:00:00 2001 From: Koncord Date: Fri, 4 Nov 2016 02:59:39 +0800 Subject: [PATCH] Add new API function: SetConsoleAllow example: tes3mp.SetConsoleAllow(pid, 0) -- disallow console to the player The console is allowed by default --- apps/openmw-mp/Script/Functions/GUI.cpp | 12 +++++++- apps/openmw-mp/Script/Functions/GUI.hpp | 5 +++- apps/openmw/mwmp/GUIController.cpp | 12 ++++++++ apps/openmw/mwmp/GUIController.hpp | 1 + apps/openmw/mwmp/LocalPlayer.cpp | 1 + apps/openmw/mwmp/Networking.cpp | 5 ++++ components/openmw-mp/Base/BasePlayer.hpp | 1 + .../Controllers/PlayerPacketController.cpp | 3 ++ components/openmw-mp/NetworkMessages.hpp | 4 ++- .../Packets/Player/PacketConsole.hpp | 29 +++++++++++++++++++ 10 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 components/openmw-mp/Packets/Player/PacketConsole.hpp diff --git a/apps/openmw-mp/Script/Functions/GUI.cpp b/apps/openmw-mp/Script/Functions/GUI.cpp index c1c3bc903..ddf355abf 100644 --- a/apps/openmw-mp/Script/Functions/GUI.cpp +++ b/apps/openmw-mp/Script/Functions/GUI.cpp @@ -67,4 +67,14 @@ void GUIFunctions::SetMapVisibility(unsigned short targetPID, unsigned short aff void GUIFunctions::SetMapVisibilityAll(unsigned short targetPID, unsigned short state) noexcept { LOG_MESSAGE(Log::LOG_WARN, "%s", "stub"); -} \ No newline at end of file +} + +void GUIFunctions::SetConsoleAllow(unsigned short pid, char state) +{ + Player *player; + GET_PLAYER(pid, player,); + + player->consoleAllowed = state; + + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_CONSOLE)->Send(player, false); +} diff --git a/apps/openmw-mp/Script/Functions/GUI.hpp b/apps/openmw-mp/Script/Functions/GUI.hpp index 845623cba..df241b1f7 100644 --- a/apps/openmw-mp/Script/Functions/GUI.hpp +++ b/apps/openmw-mp/Script/Functions/GUI.hpp @@ -11,7 +11,8 @@ {"InputDialog", GUIFunctions::InputDialog},\ {"ListBox", GUIFunctions::ListBox},\ {"SetMapVisibility", GUIFunctions::SetMapVisibility},\ - {"SetMapVisibilityAll", GUIFunctions::SetMapVisibilityAll}\ + {"SetMapVisibilityAll", GUIFunctions::SetMapVisibilityAll},\ + {"SetConsoleAllow", GUIFunctions::SetConsoleAllow}\ class GUIFunctions { @@ -27,6 +28,8 @@ public: //state 0 - disallow, 1 - allow static void SetMapVisibility(unsigned short targetPID, unsigned short affectedPID, unsigned short state) noexcept; static void SetMapVisibilityAll(unsigned short targetPID, unsigned short state) noexcept; + + static void SetConsoleAllow(unsigned short pid, char state); }; #endif //OPENMW_GUI_HPP diff --git a/apps/openmw/mwmp/GUIController.cpp b/apps/openmw/mwmp/GUIController.cpp index 56db32a5e..0ba97517e 100644 --- a/apps/openmw/mwmp/GUIController.cpp +++ b/apps/openmw/mwmp/GUIController.cpp @@ -200,6 +200,8 @@ void mwmp::GUIController::update(float dt) Main::get().getNetworking()->GetPlayerPacket(ID_GUI_MESSAGEBOX)->Send(Main::get().getLocalPlayer()); } + blockConsole(); + } void mwmp::GUIController::WM_UpdateVisible(MWGui::GuiMode mode) @@ -369,3 +371,13 @@ void mwmp::GUIController::updateGlobalMapMarkerTooltips(MWGui::MapWindow *mapWin setGlobalMapMarkerTooltip(mapWindow, markerWidget, x, y); } } + +void mwmp::GUIController::blockConsole() +{ + if (Main::get().getLocalPlayer()->consoleAllowed) + return; + + if (MWBase::Environment::get().getWindowManager()->isGuiMode()) + if (MWBase::Environment::get().getWindowManager()->getMode() == MWGui::GM_Console) + MWBase::Environment::get().getWindowManager()->popGuiMode(); +} \ No newline at end of file diff --git a/apps/openmw/mwmp/GUIController.hpp b/apps/openmw/mwmp/GUIController.hpp index a0e59f857..ad08eb018 100644 --- a/apps/openmw/mwmp/GUIController.hpp +++ b/apps/openmw/mwmp/GUIController.hpp @@ -72,6 +72,7 @@ namespace mwmp GUIDialogList *mListBox; void OnInputBoxDone(MWGui::WindowBase* parWindow); //MyGUI::Widget *oldFocusWidget, *currentFocusWidget; + void blockConsole(); }; } diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index fb21db3b6..f2221d41f 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -34,6 +34,7 @@ LocalPlayer::LocalPlayer() { CharGenStage()->current = 0; CharGenStage()->end = 1; + consoleAllowed = true; } LocalPlayer::~LocalPlayer() diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index e94f25c96..0ea4ea992 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -675,6 +675,11 @@ void Networking::ProcessPlayerPacket(RakNet::Packet *packet) } break; } + case ID_GAME_CONSOLE: + { + myPacket->Packet(&bsIn, getLocalPlayer(), false); + break; + } default: LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Unhandled PlayerPacket with identifier %i has arrived", packet->data[0]); diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index 894195efe..f20d8699d 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -168,6 +168,7 @@ namespace mwmp int day; double hour; Inventory inventory; + bool consoleAllowed; protected: ESM::Position pos; diff --git a/components/openmw-mp/Controllers/PlayerPacketController.cpp b/components/openmw-mp/Controllers/PlayerPacketController.cpp index ac146c479..49450c810 100644 --- a/components/openmw-mp/Controllers/PlayerPacketController.cpp +++ b/components/openmw-mp/Controllers/PlayerPacketController.cpp @@ -24,6 +24,7 @@ #include "../Packets/Player/PacketTime.hpp" #include "../Packets/Player/PacketLoaded.hpp" #include "../Packets/Player/PacketInventory.hpp" +#include "../Packets/Player/PacketConsole.hpp" #include "PlayerPacketController.hpp" @@ -63,6 +64,8 @@ mwmp::PlayerPacketController::PlayerPacketController(RakNet::RakPeerInterface *p AddPacket(&packets, peer); AddPacket(&packets, peer); AddPacket(&packets, peer); + + AddPacket(&packets, peer); } diff --git a/components/openmw-mp/NetworkMessages.hpp b/components/openmw-mp/NetworkMessages.hpp index 827564b33..902995efd 100644 --- a/components/openmw-mp/NetworkMessages.hpp +++ b/components/openmw-mp/NetworkMessages.hpp @@ -50,7 +50,9 @@ enum GameMessages ID_SCRIPT_LOCAL_SHORT, ID_SCRIPT_LOCAL_FLOAT, ID_SCRIPT_MEMBER_SHORT, - ID_SCRIPT_GLOBAL_SHORT + ID_SCRIPT_GLOBAL_SHORT, + + ID_GAME_CONSOLE }; diff --git a/components/openmw-mp/Packets/Player/PacketConsole.hpp b/components/openmw-mp/Packets/Player/PacketConsole.hpp new file mode 100644 index 000000000..57828a42b --- /dev/null +++ b/components/openmw-mp/Packets/Player/PacketConsole.hpp @@ -0,0 +1,29 @@ +// +// Created by koncord on 04.11.16. +// + +#ifndef OPENMW_PACKETCONSOLE_HPP +#define OPENMW_PACKETCONSOLE_HPP + +#include +#include + +namespace mwmp +{ + class PacketConsole: public PlayerPacket + { + public: + PacketConsole(RakNet::RakPeerInterface *peer) : PlayerPacket(peer) + { + packetID = ID_GAME_CONSOLE; + } + void Packet(RakNet::BitStream *bs, BasePlayer *player, bool send) + { + PlayerPacket::Packet(bs, player, send); + RW(player->consoleAllowed, send); + } + }; +} + + +#endif //OPENMW_PACKETCONSOLE_HPP