From 97af4e76aa4ae8f7e734ac011d6224163bc667b2 Mon Sep 17 00:00:00 2001 From: Sverre Rabbelier Date: Sun, 6 Apr 2008 19:35:43 +0200 Subject: [PATCH] Added a Channel editor. --- src/Core/Core.mk | 17 ++- src/Core/Core.project | 2 + src/Core/EditorChannel.cpp | 235 ++++++++++++++++++++++++++++++ src/Core/{EditorOLC.h => EditorChannel.h} | 61 +++++--- src/Core/EditorOLC.cpp | 21 ++- src/Core/EditorOLC.h | 13 +- 6 files changed, 309 insertions(+), 40 deletions(-) create mode 100644 src/Core/EditorChannel.cpp copy src/Core/{EditorOLC.h => EditorChannel.h} (60%) diff --git a/src/Core/Core.mk b/src/Core/Core.mk index 8d4651f..86011ee 100644 --- a/src/Core/Core.mk +++ b/src/Core/Core.mk @@ -34,11 +34,11 @@ endif Objects=$(IntermediateDirectory)/UBHandler$(ObjectSuffix) $(IntermediateDirectory)/UBSocket$(ObjectSuffix) $(IntermediateDirectory)/SQLSocket$(ObjectSuffix) $(IntermediateDirectory)/EditorOLC$(ObjectSuffix) $(IntermediateDirectory)/Editor$(ObjectSuffix) $(IntermediateDirectory)/EditorPermission$(ObjectSuffix) $(IntermediateDirectory)/EditorGrantGroup$(ObjectSuffix) $(IntermediateDirectory)/EditorString$(ObjectSuffix) $(IntermediateDirectory)/EditorCommand$(ObjectSuffix) $(IntermediateDirectory)/EditorScript$(ObjectSuffix) \ $(IntermediateDirectory)/EditorSector$(ObjectSuffix) $(IntermediateDirectory)/EditorRoom$(ObjectSuffix) $(IntermediateDirectory)/EditorPlaying$(ObjectSuffix) $(IntermediateDirectory)/EditorNewCharacter$(ObjectSuffix) $(IntermediateDirectory)/EditorNewAccount$(ObjectSuffix) $(IntermediateDirectory)/EditorAccount$(ObjectSuffix) $(IntermediateDirectory)/EditorMobile$(ObjectSuffix) $(IntermediateDirectory)/EditorArea$(ObjectSuffix) $(IntermediateDirectory)/EditorColour$(ObjectSuffix) $(IntermediateDirectory)/OLCEditor$(ObjectSuffix) \ - $(IntermediateDirectory)/EditorAccountLogin$(ObjectSuffix) $(IntermediateDirectory)/EditorOOC$(ObjectSuffix) $(IntermediateDirectory)/EditorChunk$(ObjectSuffix) $(IntermediateDirectory)/EditorBool$(ObjectSuffix) $(IntermediateDirectory)/EditorDetail$(ObjectSuffix) $(IntermediateDirectory)/EditorRace$(ObjectSuffix) $(IntermediateDirectory)/chunkimporter$(ObjectSuffix) $(IntermediateDirectory)/EditorCluster$(ObjectSuffix) $(IntermediateDirectory)/AccountManager$(ObjectSuffix) $(IntermediateDirectory)/AreaManager$(ObjectSuffix) \ - $(IntermediateDirectory)/CharacterManager$(ObjectSuffix) $(IntermediateDirectory)/ColourManager$(ObjectSuffix) $(IntermediateDirectory)/CommandManager$(ObjectSuffix) $(IntermediateDirectory)/GrantGroupManager$(ObjectSuffix) $(IntermediateDirectory)/MCharacterManager$(ObjectSuffix) $(IntermediateDirectory)/PCharacterManager$(ObjectSuffix) $(IntermediateDirectory)/PermissionManager$(ObjectSuffix) $(IntermediateDirectory)/RaceManager$(ObjectSuffix) $(IntermediateDirectory)/RoomManager$(ObjectSuffix) $(IntermediateDirectory)/SectorManager$(ObjectSuffix) \ - $(IntermediateDirectory)/ChunkManager$(ObjectSuffix) $(IntermediateDirectory)/DetailManager$(ObjectSuffix) $(IntermediateDirectory)/ExitManager$(ObjectSuffix) $(IntermediateDirectory)/TraceManager$(ObjectSuffix) $(IntermediateDirectory)/EchoManager$(ObjectSuffix) $(IntermediateDirectory)/ChannelManager$(ObjectSuffix) $(IntermediateDirectory)/ClusterManager$(ObjectSuffix) $(IntermediateDirectory)/Trace$(ObjectSuffix) $(IntermediateDirectory)/Sector$(ObjectSuffix) $(IntermediateDirectory)/Race$(ObjectSuffix) \ - $(IntermediateDirectory)/Room$(ObjectSuffix) $(IntermediateDirectory)/Permission$(ObjectSuffix) $(IntermediateDirectory)/MCharacter$(ObjectSuffix) $(IntermediateDirectory)/GrantGroup$(ObjectSuffix) $(IntermediateDirectory)/PCharacter$(ObjectSuffix) $(IntermediateDirectory)/Exit$(ObjectSuffix) $(IntermediateDirectory)/Echo$(ObjectSuffix) $(IntermediateDirectory)/Detail$(ObjectSuffix) $(IntermediateDirectory)/Command$(ObjectSuffix) $(IntermediateDirectory)/Colour$(ObjectSuffix) \ - $(IntermediateDirectory)/Chunk$(ObjectSuffix) $(IntermediateDirectory)/Character$(ObjectSuffix) $(IntermediateDirectory)/Channel$(ObjectSuffix) $(IntermediateDirectory)/Area$(ObjectSuffix) $(IntermediateDirectory)/Account$(ObjectSuffix) $(IntermediateDirectory)/Savable$(ObjectSuffix) $(IntermediateDirectory)/Cluster$(ObjectSuffix) + $(IntermediateDirectory)/EditorAccountLogin$(ObjectSuffix) $(IntermediateDirectory)/EditorOOC$(ObjectSuffix) $(IntermediateDirectory)/EditorChunk$(ObjectSuffix) $(IntermediateDirectory)/EditorBool$(ObjectSuffix) $(IntermediateDirectory)/EditorDetail$(ObjectSuffix) $(IntermediateDirectory)/EditorRace$(ObjectSuffix) $(IntermediateDirectory)/chunkimporter$(ObjectSuffix) $(IntermediateDirectory)/EditorCluster$(ObjectSuffix) $(IntermediateDirectory)/EditorChannel$(ObjectSuffix) $(IntermediateDirectory)/AccountManager$(ObjectSuffix) \ + $(IntermediateDirectory)/AreaManager$(ObjectSuffix) $(IntermediateDirectory)/CharacterManager$(ObjectSuffix) $(IntermediateDirectory)/ColourManager$(ObjectSuffix) $(IntermediateDirectory)/CommandManager$(ObjectSuffix) $(IntermediateDirectory)/GrantGroupManager$(ObjectSuffix) $(IntermediateDirectory)/MCharacterManager$(ObjectSuffix) $(IntermediateDirectory)/PCharacterManager$(ObjectSuffix) $(IntermediateDirectory)/PermissionManager$(ObjectSuffix) $(IntermediateDirectory)/RaceManager$(ObjectSuffix) $(IntermediateDirectory)/RoomManager$(ObjectSuffix) \ + $(IntermediateDirectory)/SectorManager$(ObjectSuffix) $(IntermediateDirectory)/ChunkManager$(ObjectSuffix) $(IntermediateDirectory)/DetailManager$(ObjectSuffix) $(IntermediateDirectory)/ExitManager$(ObjectSuffix) $(IntermediateDirectory)/TraceManager$(ObjectSuffix) $(IntermediateDirectory)/EchoManager$(ObjectSuffix) $(IntermediateDirectory)/ChannelManager$(ObjectSuffix) $(IntermediateDirectory)/ClusterManager$(ObjectSuffix) $(IntermediateDirectory)/Trace$(ObjectSuffix) $(IntermediateDirectory)/Sector$(ObjectSuffix) \ + $(IntermediateDirectory)/Race$(ObjectSuffix) $(IntermediateDirectory)/Room$(ObjectSuffix) $(IntermediateDirectory)/Permission$(ObjectSuffix) $(IntermediateDirectory)/MCharacter$(ObjectSuffix) $(IntermediateDirectory)/GrantGroup$(ObjectSuffix) $(IntermediateDirectory)/PCharacter$(ObjectSuffix) $(IntermediateDirectory)/Exit$(ObjectSuffix) $(IntermediateDirectory)/Echo$(ObjectSuffix) $(IntermediateDirectory)/Detail$(ObjectSuffix) $(IntermediateDirectory)/Command$(ObjectSuffix) \ + $(IntermediateDirectory)/Colour$(ObjectSuffix) $(IntermediateDirectory)/Chunk$(ObjectSuffix) $(IntermediateDirectory)/Character$(ObjectSuffix) $(IntermediateDirectory)/Channel$(ObjectSuffix) $(IntermediateDirectory)/Area$(ObjectSuffix) $(IntermediateDirectory)/Account$(ObjectSuffix) $(IntermediateDirectory)/Savable$(ObjectSuffix) $(IntermediateDirectory)/Cluster$(ObjectSuffix) ## ## Main Build Tragets @@ -198,6 +198,11 @@ $(IntermediateDirectory)/EditorCluster$(ObjectSuffix): EditorCluster.cpp $(Inter $(IntermediateDirectory)/EditorCluster$(ObjectSuffix).d: @$(CompilerName) $(CmpOptions) $(IncludePath) -MT$(IntermediateDirectory)/EditorCluster$(ObjectSuffix) -MF$(IntermediateDirectory)/EditorCluster$(ObjectSuffix).d -MM EditorCluster.cpp +$(IntermediateDirectory)/EditorChannel$(ObjectSuffix): EditorChannel.cpp $(IntermediateDirectory)/EditorChannel$(ObjectSuffix).d + $(CompilerName) $(SourceSwitch)EditorChannel.cpp $(CmpOptions) $(ObjectSwitch)$(IntermediateDirectory)/EditorChannel$(ObjectSuffix) $(IncludePath) +$(IntermediateDirectory)/EditorChannel$(ObjectSuffix).d: + @$(CompilerName) $(CmpOptions) $(IncludePath) -MT$(IntermediateDirectory)/EditorChannel$(ObjectSuffix) -MF$(IntermediateDirectory)/EditorChannel$(ObjectSuffix).d -MM EditorChannel.cpp + $(IntermediateDirectory)/AccountManager$(ObjectSuffix): AccountManager.cpp $(IntermediateDirectory)/AccountManager$(ObjectSuffix).d $(CompilerName) $(SourceSwitch)AccountManager.cpp $(CmpOptions) $(ObjectSwitch)$(IntermediateDirectory)/AccountManager$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/AccountManager$(ObjectSuffix).d: @@ -453,6 +458,8 @@ clean: $(RM) $(IntermediateDirectory)/chunkimporter$(ObjectSuffix).d $(RM) $(IntermediateDirectory)/EditorCluster$(ObjectSuffix) $(RM) $(IntermediateDirectory)/EditorCluster$(ObjectSuffix).d + $(RM) $(IntermediateDirectory)/EditorChannel$(ObjectSuffix) + $(RM) $(IntermediateDirectory)/EditorChannel$(ObjectSuffix).d $(RM) $(IntermediateDirectory)/AccountManager$(ObjectSuffix) $(RM) $(IntermediateDirectory)/AccountManager$(ObjectSuffix).d $(RM) $(IntermediateDirectory)/AreaManager$(ObjectSuffix) diff --git a/src/Core/Core.project b/src/Core/Core.project index fe0ab9e..6eff498 100644 --- a/src/Core/Core.project +++ b/src/Core/Core.project @@ -41,6 +41,7 @@ + @@ -68,6 +69,7 @@ + diff --git a/src/Core/EditorChannel.cpp b/src/Core/EditorChannel.cpp new file mode 100644 index 0000000..8aefe58 --- /dev/null +++ b/src/Core/EditorChannel.cpp @@ -0,0 +1,235 @@ +/*************************************************************************** + * Copyright (C) 2008 by Sverre Rabbelier * + * sverre@rabbelier.nl * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "EditorChannel.h" +#include "EditorString.h" +#include "EditorBool.h" + +#include "UBSocket.h" + +#include "StringUtilities.h" +#include "TableImpls.h" +#include "Array.h" + +#include "Account.h" +#include "Channel.h" +#include "ChannelManager.h" + +typedef EditorChannel E; +typedef CommandInfoObject O; +typedef CommandBinding B; + +// name function need: object lock +static O editName( "Name", &E::editName, true, true); +static O editDescription("Description",&E::editDescription,true, true); +static O editNeedLogin("NeedLogin", &E::editNeedLogin, true, true); +static O showChannel( "Show", &E::showChannel, true, false); +static O saveChannel( "Save", &E::saveChannel, true, true); + +static B commands[] = { + B("description", editDescription), + B("name", editName), + B("needlogin", editNeedLogin), + B("save", saveChannel), + B("show", showChannel), +}; + +EditorChannel::EditorChannel(UBSocket* sock) : +OLCEditor(sock), +m_commands(commands, array_size(commands)), +m_channel() +{ + listCommands(Global::Get()->EmptyString); +} + +EditorChannel::~EditorChannel(void) +{ + +} + +void EditorChannel::OnFocus() +{ + switch(m_target) + { + case M_NONE: + return; + + case M_DESCRIPTION: + m_channel->setDescription(m_value); + break; + + case M_NEEDLOGIN: + m_channel->setNeedLogin(m_yesno); + break; + } + + m_target = M_NONE; +} + +std::string EditorChannel::lookup(const std::string& action) +{ + std::string name = OLCEditor::lookup(action); + if(name.size() != 0) + return name; + + const ChannelCommand* act = (ChannelCommand*)m_commands.getObject(action); + if(act) + return act->getName(); + + return Global::Get()->EmptyString; +} + +void EditorChannel::dispatch(const std::string& action, const std::string& argument) +{ + const ChannelCommand* act = (ChannelCommand*)m_commands.getObject(action); + + if(!act) + { + OLCEditor::dispatch(action, argument); + return; + } + + if(!m_channel) + { + m_sock->Send("You need to be editing an channel first.\n"); + m_sock->Send("(Use the 'edit' command.)\n"); + return; + } + + if(act->needLock()) + { + try { + m_channel->Lock(); + } catch(SavableLocked& e) { + m_sock->Send("The channel you are currently editing is locked (being edited by someone else), so you cannot edit it right now.\n"); + m_sock->Send("Please try again later.\n"); + return; + } + } + + act->Run(this, argument); + return; +} + +SavablePtr EditorChannel::getEditing() +{ + return m_channel; +} + +TableImplPtr EditorChannel::getTable() +{ + return db::TableImpls::Get()->AREAS; +} + +KeysPtr EditorChannel::addNew() +{ + return mud::ChannelManager::Get()->Add(); +} + +std::vector EditorChannel::getList() +{ + return mud::ChannelManager::Get()->List(); +} + +void EditorChannel::setEditing(KeysPtr keys) +{ + if(!keys->size()) + { + m_channel.reset(); + return; + } + + m_channel = mud::ChannelManager::Get()->GetByKey(keys->first()->getIntegerValue()); + return; +} + +std::vector EditorChannel::getCommands() +{ + return m_commands.getCommandsVector(); +} + +void EditorChannel::editName(const std::string& argument) +{ + if(argument.size() == 0) + { + m_sock->Send("Channel name can't be zero length!\n"); + return; + } + + m_sock->Sendf("Channel name changed from '%s' to '%s'.\n", m_channel->getName().c_str(), argument.c_str()); + m_channel->setName(argument); + return; +} + +void EditorChannel::editDescription(const std::string& argument) +{ + if(argument.size() == 0) + { + m_sock->Send("No argument, dropping you into the string editor!\n"); + m_sock->SetEditor(new EditorString(m_sock, m_value)); + m_target = M_DESCRIPTION; + return; + + return; + } + + m_sock->Sendf("Channel description changed from '%s' to '%s'.\n", m_channel->getDescription().c_str(), argument.c_str()); + m_channel->setDescription(argument); + return; +} + +void EditorChannel::editNeedLogin(const std::string& argument) +{ + if(argument.size() == 0) + { + m_sock->Send("Do players need to be logged in to use hear the channel?\n"); + m_sock->SetEditor(new EditorBool(m_sock, m_yesno)); + m_target = M_NEEDLOGIN; + return; + } + + if(!argument.compare("yes")) + { + m_channel->setNeedLogin(true); + return; + } + + if(!argument.compare("no")) + { + m_channel->setNeedLogin(false); + return; + } + + editNeedLogin(Global::Get()->EmptyString); + return; +} + +void EditorChannel::showChannel(const std::string& argument) +{ + m_sock->Send(m_channel->toString()); +} + +void EditorChannel::saveChannel(const std::string& argument) +{ + m_sock->Sendf("Saving channel '%s'.\n", m_channel->getName().c_str()); + m_channel->Save(); + m_sock->Send("Saved.\n"); + return; +} diff --git a/src/Core/EditorOLC.h b/src/Core/EditorChannel.h similarity index 60% copy from src/Core/EditorOLC.h copy to src/Core/EditorChannel.h index 9b59a23..cae0622 100644 --- a/src/Core/EditorOLC.h +++ b/src/Core/EditorChannel.h @@ -21,40 +21,55 @@ #include "Types.h" -#include "Editor.h" -#include "CommandObject.h" +#include "OLCEditor.h" +#include "CommandInfoObject.h" #include "CommandTable.h" -class EditorOLC : public Editor +class EditorChannel : public OLCEditor { public: - typedef CommandObject OLCCommand; /**< The type of a CommandObject for this Editor. */ + typedef CommandInfoObject ChannelCommand; /**< The type of a CommandInfoObject for this Editor. */ - EditorOLC(UBSocket* sock); - ~EditorOLC(void); + EditorChannel(UBSocket* sock); + ~EditorChannel(void); + + void OnFocus(); - std::string name() { return "OLC"; }; - std::string prompt() { return "OLC> "; }; + std::string name() { return "Channel"; }; + std::string prompt() { return "Channel> "; }; std::string lookup(const std::string& action); void dispatch(const std::string& action, const std::string& argument); - void startAreas(const std::string& argument); - void startRooms(const std::string& argument); - void startScripts(const std::string& argument); - void startMobiles(const std::string& argument); - void startSectors(const std::string& argument); - void startColours(const std::string& argument); - void startCommands(const std::string& argument); - void startChunks(const std::string& argument); - void startRaces(const std::string& argument); - void startDetails(const std::string& argument); - void listCommands(const std::string& argument); - void quitEditor(const std::string& argument); + SavablePtr getEditing(); + TableImplPtr getTable(); + KeysPtr addNew(); + std::vector getList(); + std::vector getCommands(); + void setEditing(KeysPtr keys); + + void editName(const std::string& argument); + void editDescription(const std::string& argument); + void editNeedLogin(const std::string& argument); + void showChannel(const std::string& argument); + void saveChannel(const std::string& argument); private: - CommandTable m_commands; + CommandTable m_commands; + mud::ChannelPtr m_channel; + + enum E_TARGET + { + M_NONE, + M_DESCRIPTION, + M_NEEDLOGIN, + }; + + std::string m_value; + bool m_yesno; + + EditorChannel::E_TARGET m_target; - EditorOLC(const EditorOLC& rhs); - EditorOLC operator=(const EditorOLC& rhs); + EditorChannel(const EditorChannel& rhs); + EditorChannel operator=(const EditorChannel& rhs); }; diff --git a/src/Core/EditorOLC.cpp b/src/Core/EditorOLC.cpp index 85e6f45..ef9328c 100644 --- a/src/Core/EditorOLC.cpp +++ b/src/Core/EditorOLC.cpp @@ -30,6 +30,7 @@ #include "EditorChunk.h" #include "EditorRace.h" #include "EditorDetail.h" +#include "EditorChannel.h" #include "Account.h" #include "Array.h" @@ -42,21 +43,23 @@ typedef CommandObject O; typedef CommandBinding B; static O startAreas("Areas", &E::startAreas); -static O startRooms("Rooms", &E::startRooms); +static O startChannels("Channels", &E::startChannels); static O startChunks("Chunks", &E::startChunks); -static O startDetails("Details", &E::startDetails); -static O startScripts("Scripts", &E::startScripts); -static O startMobiles("Mobiles", &E::startMobiles); -static O startSectors("Sectors", &E::startSectors); static O startColours("Colours", &E::startColours); static O startCommands("Commands", &E::startCommands); +static O startDetails("Details", &E::startDetails); +static O startMobiles("Mobiles", &E::startMobiles); static O startRaces("Races", &E::startRaces); +static O startRooms("Rooms", &E::startRooms); +static O startScripts("Scripts", &E::startScripts); +static O startSectors("Sectors", &E::startSectors); static O listCommands("?", &E::listCommands); static O quitEditor("Quit", &E::quitEditor); static B commands[] = { B("?", listCommands), B("areas", startAreas), + B("channels", startChannels), B("chunks", startChunks), B("colour", startColours), B("commands", startCommands), @@ -105,7 +108,6 @@ void EditorOLC::startAreas(const std::string& argument) return; } - void EditorOLC::startRooms(const std::string& argument) { m_sock->Send("Dropping you into Room Edit mode!\n"); @@ -162,6 +164,13 @@ void EditorOLC::startDetails(const std::string& argument) return; } +void EditorOLC::startChannels(const std::string& argument) +{ + m_sock->Send("Dropping you into Channel Edit mode!\n"); + m_sock->SetEditor(new EditorChannel(m_sock)); + return; +} + void EditorOLC::startScripts(const std::string& argument) { m_sock->Send("Dropping you into Script Edit mode!\n"); diff --git a/src/Core/EditorOLC.h b/src/Core/EditorOLC.h index 9b59a23..3137095 100644 --- a/src/Core/EditorOLC.h +++ b/src/Core/EditorOLC.h @@ -40,15 +40,16 @@ public: void dispatch(const std::string& action, const std::string& argument); void startAreas(const std::string& argument); - void startRooms(const std::string& argument); - void startScripts(const std::string& argument); - void startMobiles(const std::string& argument); - void startSectors(const std::string& argument); + void startChannels(const std::string& argument); + void startChunks(const std::string& argument); void startColours(const std::string& argument); void startCommands(const std::string& argument); - void startChunks(const std::string& argument); - void startRaces(const std::string& argument); void startDetails(const std::string& argument); + void startMobiles(const std::string& argument); + void startRaces(const std::string& argument); + void startRooms(const std::string& argument); + void startScripts(const std::string& argument); + void startSectors(const std::string& argument); void listCommands(const std::string& argument); void quitEditor(const std::string& argument); -- 2.11.4.GIT