diff --git a/code/ryzom/client/src/net_manager.cpp b/code/ryzom/client/src/net_manager.cpp index 2d5a4e2be..d8ccbc263 100644 --- a/code/ryzom/client/src/net_manager.cpp +++ b/code/ryzom/client/src/net_manager.cpp @@ -25,7 +25,6 @@ #include "game_share/generic_xml_msg_mngr.h" #include "game_share/msg_client_server.h" #include "game_share/bot_chat_types.h" -#include "game_share/news_types.h" #include "game_share/mode_and_behaviour.h" #include "game_share/chat_group.h" #include "game_share/character_summary.h" diff --git a/code/ryzom/common/src/game_share/news_types.h b/code/ryzom/common/src/game_share/news_types.h deleted file mode 100644 index e9427766a..000000000 --- a/code/ryzom/common/src/game_share/news_types.h +++ /dev/null @@ -1,36 +0,0 @@ -// Ryzom - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero 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 Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - - -#ifndef RY_NEWS_TYPES_H -#define RY_NEWS_TYPES_H - -namespace NEWSTYPE -{ - enum TNewsType - { - Unknown, - General, - FyrosWorker, - FyrosTrainer, - FyrosGeneral, - }; -}; - -#endif // RY_NEWS_TYPES_H - -/* End of news_types.h */ diff --git a/code/ryzom/server/src/ai_service/aids_interface.h b/code/ryzom/server/src/ai_service/aids_interface.h index 21b8c76bd..3e9d9898f 100644 --- a/code/ryzom/server/src/ai_service/aids_interface.h +++ b/code/ryzom/server/src/ai_service/aids_interface.h @@ -23,7 +23,6 @@ // Nel Misc #include "nel/misc/types_nl.h" #include "nel/misc/entity_id.h" -#include "game_share/news_types.h" #include "game_share/bot_chat_types.h" // the class diff --git a/code/ryzom/server/src/ai_service/bot_chat_interface.cpp b/code/ryzom/server/src/ai_service/bot_chat_interface.cpp deleted file mode 100644 index 36dc9aa42..000000000 --- a/code/ryzom/server/src/ai_service/bot_chat_interface.cpp +++ /dev/null @@ -1,1160 +0,0 @@ -// Ryzom - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero 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 Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - - -#include "stdpch.h" -#if 0 -#error "Deprecated" -//#include "bot_chat_interface.h" -#include "game_share/synchronised_message.h" -#include "game_share/bot_chat_types.h" - -/* -// Nel Misc -#include "nel/net/unified_network.h" - -// Game share -#include "game_share/news_types.h" -#include "game_share/bot_chat_types.h" - -// Local includes -#include "bot_chat_interface.h" -*/ - -using namespace NLMISC; -using namespace NLNET; -using namespace std; - -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////////// -// the parent class for bot chat page type classes - -class CBotChatPageType -{ -public: - // virtual interface ---------------------------------------------------- - virtual bool open(const CEntityId &player, const CEntityId &bot)=0; - virtual bool close(const CEntityId &player, const CEntityId &bot)=0; -}; - - -////////////////////////////////////////////////////////////////////////////// -// the structure for bot chat pages - -struct SBotChatPage -{ - // ctor ----------------------------------------------------------------- - SBotChatPage( - BOTCHATTYPE::TBotChatInterfaceId clientInterfaceId, - CBotChatPageType * chatPageType, - uint numOptions - ) - { - ClientInterfaceId= clientInterfaceId; - PageType= chatPageType; - NumOptions= numOptions; - } - - // data ----------------------------------------------------------------- - BOTCHATTYPE::TBotChatInterfaceId ClientInterfaceId; // id of interface to display on client - CBotChatPageType * PageType; // type of chat page - uint NumOptions; // number of options for player to click on -}; - - -////////////////////////////////////////////////////////////////////////////// -// the structure for a state for bot chat automatons - -struct SBotChatAutomatonState -{ - // public data ---------------------------------------------------------- - SBotChatPage *Page; - uint On[5]; // value to return on player click of slot 0..4 - - // ctor ----------------------------------------------------------------- - SBotChatAutomatonState(SBotChatPage *page,uint on0=std::numeric_limits::max(),uint on1=std::numeric_limits::max(),uint on2=std::numeric_limits::max(),uint on3=std::numeric_limits::max(),uint on4=std::numeric_limits::max()) - { - Page=page; - On[0]=on0; - On[1]=on1; - On[2]=on2; - On[3]=on3; - On[4]=on4; - - // make sure the number of arguments supplied corresponds to the - // number of options prresent on the user interfac page - nlassert(page->NumOptions>=0 && page->NumOptions<=4); - nlassert(page->NumOptions==0 || On[page->NumOptions-1]!=std::numeric_limits::max()); - nlassert(page->NumOptions==4 || On[page->NumOptions]==std::numeric_limits::max()); - } -}; - - -////////////////////////////////////////////////////////////////////////////// -// the structure for a bot chat automatons & a singleton for indexing -// automatons by name - -struct SBotChatAutomaton -{ - // public data ---------------------------------------------------------- - string Name; - SBotChatAutomatonState *States; - uint Size; - - // ctor ----------------------------------------------------------------- - SBotChatAutomaton(string name, SBotChatAutomatonState *states,uint size) - { - Name=name; - States=states; - Size=size; - - if (NameMap.find(name)!=NameMap.end()) - { - nlwarning("SBotChatAutomaton::SBotChatAutomaton(): More than one instance with name: %s",name.c_str()); - return; - } - NameMap[name]=this; - } - - // dtor ----------------------------------------------------------------- - ~SBotChatAutomaton() - { - map ::iterator it=NameMap.find(Name); - if (it!=NameMap.end() && (*it).second==this) - NameMap.erase(it); - // don't try to display a warning in a dtor as the warning system is - // probably already down - } - - - // singleton methods ---------------------------------------------------- - static SBotChatAutomaton *getAutomatonByName(string name) - { - map ::iterator it=NameMap.find(name); - if (it==NameMap.end()) - return NULL; - return (*it).second; - } - - // singleton data ------------------------------------------------------- - static map NameMap; -}; -map SBotChatAutomaton::NameMap; - - -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -// Implementation of different code modules for handling different bot -// chat page types - -////////////////////////////////////////////////////////////////////////////// -// this is a dummy page used to terminate chats - -class CBotChatPageTypeDone: public CBotChatPageType -{ -public: - virtual bool open(const CEntityId &player, const CEntityId &bot) - { - return false; // stop the bot chat! - } - - virtual bool close(const CEntityId &player, const CEntityId &bot) - { - return false; - } -} -BotChatPageTypeDone; - - -////////////////////////////////////////////////////////////////////////////// -// definition for a chat page that contains static text and buttons for -// player to click on/ select - -class CBotChatPageTypeTextOnly: public CBotChatPageType -{ -public: - virtual bool open(const CEntityId &player, const CEntityId &bot) - { - return true; - } - - virtual bool close(const CEntityId &player, const CEntityId &bot) - { - return true; - } -} -BotChatPageTypeTextOnly; - - -////////////////////////////////////////////////////////////////////////////// -// definition for a chat page that displays NEWS as well as other text - -class CBotChatPageTypeNews: public CBotChatPageType -{ -public: - virtual bool open(const CEntityId &player, const CEntityId &bot) - { - return true; - } - - virtual bool close(const CEntityId &player, const CEntityId &bot) - { - return true; - } -} -BotChatPageTypeNews; - - -////////////////////////////////////////////////////////////////////////////// -// definition for a chat page that displays a SHOP interface - -class CBotChatPageTypeShop: public CBotChatPageType -{ -public: - virtual bool open(const CEntityId &player, const CEntityId &bot) - { - nlinfo ("player %s entered trade page", player.toString().c_str()); - CMessage msgout( "TRADE_BEGIN" ); - msgout.serial( const_cast(player) ); - msgout.serial( const_cast(bot) ); - sendMessageViaMirror( "WOS", msgout ); - return true; - } - - virtual bool close(const CEntityId &player, const CEntityId &bot) - { - nlinfo ("end of trade with player %s", player.toString().c_str()); - CMessage msgout( "TRADE_END" ); - msgout.serial( const_cast(player) ); - msgout.serial( const_cast(bot) ); - sendMessageViaMirror( "WOS", msgout ); - sendMessageViaMirror( "EGS", msgout ); - return true; - } -} -BotChatPageTypeShop; - - -////////////////////////////////////////////////////////////////////////////// -// definition for a chat page that displays a MISSION SHOP interface - -class CBotChatPageTypeMissionShop: public CBotChatPageType -{ -public: - virtual bool open(const CEntityId &player, const CEntityId &bot) - { - nlinfo ("player %s entered mission page", player.toString().c_str()); - CMessage msgout( "MISSION_LIST_BEGIN" ); - msgout.serial( const_cast(player) ); - msgout.serial( const_cast(bot) ); - sendMessageViaMirror( "WOS", msgout ); - return true; - } - - virtual bool close(const CEntityId &player, const CEntityId &bot) - { - nlinfo ("end of mission page with player %s", player.toString().c_str()); - CMessage msgout( "MISSION_LIST_END" ); - msgout.serial( const_cast(player) ); - msgout.serial( const_cast(bot) ); - sendMessageViaMirror( "EGS", msgout ); - return true; - } -} -BotChatPageTypeMissionShop; - - - -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -// Definitions of bot chat pages and automatons - -// define the usable bot chat pages ------------------------------------------ -SBotChatPage BotChatPageIntro (BOTCHATTYPE::Intro, &BotChatPageTypeTextOnly, 4); -SBotChatPage BotChatPageFriendly (BOTCHATTYPE::FriendlyMainPage, &BotChatPageTypeNews, 4); -SBotChatPage BotChatPageNeutral (BOTCHATTYPE::NeutralMainPage, &BotChatPageTypeNews, 3); -SBotChatPage BotChatPageHostile (BOTCHATTYPE::NastyMainPage, &BotChatPageTypeTextOnly, 1); -SBotChatPage BotChatPageMoreNews (BOTCHATTYPE::MoreNewsPage, &BotChatPageTypeNews, 2); -SBotChatPage BotChatPageShop (BOTCHATTYPE::BuySellPage, &BotChatPageTypeShop, 2); -SBotChatPage BotChatPageMissionShop (BOTCHATTYPE::MissionsPage, &BotChatPageTypeMissionShop, 2); -SBotChatPage BotChatPageDone (BOTCHATTYPE::Done, &BotChatPageTypeDone, 0); - -// the default automaton ----------------------------------------------------- -SBotChatAutomatonState BotChatStatesDefault[]= -{ - SBotChatAutomatonState(&BotChatPageIntro,2,3,4,1), // 0 - friendly/ neutral/ hostile/ done - SBotChatAutomatonState(&BotChatPageDone), // 1 - SBotChatAutomatonState(&BotChatPageFriendly,5,6,7,1), // 2 - more news/ buy sell/ mission/ done - SBotChatAutomatonState(&BotChatPageNeutral,6,7,1), // 3 - buy sell/ mission/ done - SBotChatAutomatonState(&BotChatPageHostile,1), // 4 - done - SBotChatAutomatonState(&BotChatPageMoreNews,2,1), // 5 - friendly/ done - SBotChatAutomatonState(&BotChatPageShop,3,1), // 6 - neutral/ done - SBotChatAutomatonState(&BotChatPageMissionShop,3,1), // 7 - neutral/ done -}; -SBotChatAutomaton BotChatDefault("default",BotChatStatesDefault,sizeof(BotChatStatesDefault)/sizeof(BotChatStatesDefault[0])); - -// the automaton for merchants ----------------------------------------------- -SBotChatAutomatonState BotChatStatesMerchant[]= -{ - SBotChatAutomatonState(&BotChatPageMoreNews,2,1), // 0 - shop/ done - SBotChatAutomatonState(&BotChatPageDone), // 1 - SBotChatAutomatonState(&BotChatPageShop,0,1), // 2 - news/ done -}; -SBotChatAutomaton BotChatMerchant("merchant",BotChatStatesMerchant,sizeof(BotChatStatesMerchant)/sizeof(BotChatStatesMerchant[0])); - -// the automaton for walkers and talkers ------------------------------------- -SBotChatAutomatonState BotChatStatesWalkerTalker[]= -{ - SBotChatAutomatonState(&BotChatPageHostile,1), // 0 - SBotChatAutomatonState(&BotChatPageDone) // 1 -}; -SBotChatAutomaton BotChatWalkerTalker("walker talker",BotChatStatesWalkerTalker,sizeof(BotChatStatesMerchant)/sizeof(BotChatStatesMerchant[0])); - - -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -// Represetnation of a conversation between a player and a bot -// includes conversation automaton state data - -struct CBotChat -{ - CBotChat () : Player(CEntityId::Unknown), Bot(CEntityId::Unknown) { } - CBotChat (CEntityId player, CEntityId bot, SBotChatAutomaton *automaton) - { - Player=player; - Bot=bot; - setAutomaton(automaton); - } - - void setState(uint32 state) - { - if (state>=Automaton->Size && state!=std::numeric_limits::max()) - { - nlwarning("CBotChatEntry()::setState: Invalid state: %d",state); - return; - } - - // if there is already a page open close it - if (CurrentStateSize) - Automaton->States[CurrentState].Page->PageType->close(Player,Bot); - - // open the new page - CurrentState=state; - if (state==std::numeric_limits::max()) - Done=true; - else - Done=!Automaton->States[CurrentState].Page->PageType->open(Player,Bot); - - // transmit the new page id to the client - uint32 happyness=10; - BOTCHATTYPE::TBotChatInterfaceId interfaceId=Done?BOTCHATTYPE::Done:Automaton->States[CurrentState].Page->ClientInterfaceId; - NEWSTYPE::TNewsType newsType=NEWSTYPE::Unknown; - - CMessage msgout("BOT_CHAT_SELECT_INTERFACE"); - msgout.serial (Player); - msgout.serial (happyness); - msgout.serialEnum (interfaceId); - msgout.serialEnum (newsType); - sendMessageViaMirror("IOS", msgout); - } - - void setAutomaton(SBotChatAutomaton *automaton) - { - Automaton=automaton; - CurrentState=std::numeric_limits::max(); // set this to a ~0 so that setState doesn't try to clse existing page - setState(0); - } - - void selectEntry (sint8 userInput) - { - // select the new page - if ((unsigned)userInput >= Automaton->States[CurrentState].Page->NumOptions) - { - nlwarning ("CBotChatEntry::selectEntry: For player %s: input out of bounds: %d", Player.toString().c_str(), userInput); - return; - } - - // advance through the state table - setState(Automaton->States[CurrentState].On[userInput]); - } - - void endChat () - { - setState(std::numeric_limits::max()); - } - - CEntityId Player; - CEntityId Bot; - SBotChatAutomaton *Automaton; - uint32 CurrentState; - bool Done; -}; - - -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -// Singleton manager class central to the bot chat system - -class CBotChatManager -{ -public: - - static void newChat(CEntityId player, CEntityId bot) - { - // make sure the player isn't already chatting - map::iterator it = BotChatMap.find (player); - if (it != BotChatMap.end()) - return; - - // a bit of logging - nlinfo ("new chat between player %s and bot %s", player.toString().c_str(), bot.toString().c_str()); - - // call the CbBegin() callback to get the name of the automaton to use - string automatonName; - if (CbBegin!=NULL) - automatonName=CbBegin(player,bot); - else - automatonName="default"; - SBotChatAutomaton *automaton=SBotChatAutomaton::getAutomatonByName(automatonName); - if (automaton==NULL) - { - nlwarning("- ignoring bot chat request as automaton '%s' not found",automatonName.c_str()); - return; - } - - // setup the new chat - BotChatMap[player] = CBotChat(player, bot, automaton); - } - - static void endChat(CEntityId player) - { - CEntityId bot; // for use in callback ... at end of routine - - map::iterator it = BotChatMap.find (player); - if (it != BotChatMap.end()) - { - bot=(*it).second.Bot; - - nlinfo ("end of bot chat between player %s and bot %s", player.toString().c_str(),bot.toString().c_str()); - - // if the chat is still active then stop it - if ((*it).second.Done) - (*it).second.endChat(); - - // remove the map entry - BotChatMap.erase (it); - - // **** this code may be dodgy 'cos its in a dtor - // **** if it is dodgy then we need to migrate from an STL map - // **** to some kind of custom structure that we can guarantee OK - } - - if (CbEnd!=NULL) - CbEnd(player,bot); - } - - static void treatInput(CEntityId player, sint8 userInput) - { - // locate the bot chat for the given player - map::iterator it = BotChatMap.find (player); - if (it == BotChatMap.end()) - { - nlwarning ("No bot chat with the player %s", player.toString().c_str()); - return; - } - - // pass the player input to the bot chat handler - (*it).second.selectEntry(userInput); - - // check whether the bot chat is finished - if ((*it).second.Done) - endChat(player); - } - - - // static data for the singleton ----------------------------------------- - static CBotChatInterface::TCallbackBegin CbBegin; - static CBotChatInterface::TCallbackEnd CbEnd; - static map BotChatMap; -}; -CBotChatInterface::TCallbackBegin CBotChatManager::CbBegin; -CBotChatInterface::TCallbackEnd CBotChatManager::CbEnd; -map CBotChatManager::BotChatMap; - - -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -// message callbacks and callback table - -static void cbBotChatStart (CMessage& msgin, const string &serviceName, uint16 serviceId ) -{ - CEntityId player, bot; - - msgin.serial( player ); - msgin.serial( bot ); - - CBotChatManager::newChat (player, bot); -} - -static void cbBotChatSelectAnswer (CMessage& msgin, const string &serviceName, uint16 serviceId ) -{ - CEntityId player, bot; - sint8 answer; - - msgin.serial( player ); - msgin.serial( answer ); - - CBotChatManager::treatInput (player, answer); -} - - -static TUnifiedCallbackItem CbArray[]= -{ - { "BOT_CHAT_START", cbBotChatStart }, - { "BOT_CHAT_SELECT_ANSWER", cbBotChatSelectAnswer }, -}; - - -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -// Interface class providing API for bot chat system - -void CBotChatInterface::init(CBotChatInterface::TCallbackBegin cbBegin,CBotChatInterface::TCallbackEnd cbEnd) -{ - CBotChatManager::CbBegin=cbBegin; - CBotChatManager::CbEnd=cbEnd; - CUnifiedNetwork::getInstance()->addCallbackArray(CbArray, sizeof (CbArray) / sizeof (CbArray[0])); -} - -void CBotChatInterface::release() -{ -} - -void CBotChatInterface::getBotChatPartners(CEntityId bot,vector &result) -{ - map::iterator it; - for (it=CBotChatManager::BotChatMap.begin();it!=CBotChatManager::BotChatMap.end();++it) - if ((*it).second.Bot==bot) - result.push_back((*it).first); -} - -void CBotChatInterface::endChatForPlayer(CEntityId player) -{ - CBotChatManager::endChat(player); -} - -void CBotChatInterface::endAllChatForBot(CEntityId bot) -{ - map::iterator it=CBotChatManager::BotChatMap.begin(); - while (it!=CBotChatManager::BotChatMap.end()) - { - map::iterator next=it; - if ((*it).second.Bot==bot) - CBotChatManager::endChat((*it).first); - it=next; - } -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -////////////////////// -/// The following is probably out of date but I'm copying it here just in case... - - - -#if 0 - - - - -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////////// -// the parent class for bot chat page type classes - -class CBotChatPageType -{ -public: - // virtual interface ---------------------------------------------------- - virtual bool open(const CEntityId &player, const CEntityId &bot)=0; - virtual bool close(const CEntityId &player, const CEntityId &bot)=0; -}; - - -////////////////////////////////////////////////////////////////////////////// -// the structure for bot chat pages - -struct SBotChatPage -{ - // ctor ----------------------------------------------------------------- - SBotChatPage( - BOTCHATTYPE::TBotChatInterfaceId clientInterfaceId, - CBotChatPageType * chatPageType, - uint numOptions - ) - { - ClientInterfaceId= clientInterfaceId; - PageType= chatPageType; - NumOptions= numOptions; - } - - // data ----------------------------------------------------------------- - BOTCHATTYPE::TBotChatInterfaceId ClientInterfaceId; // id of interface to display on client - CBotChatPageType * PageType; // type of chat page - uint NumOptions; // number of options for player to click on -}; - - -////////////////////////////////////////////////////////////////////////////// -// the structure for a state for bot chat automatons - -struct SBotChatAutomatonState -{ - // public data ---------------------------------------------------------- - SBotChatPage *Page; - uint On[5]; // value to return on player click of slot 0..4 - - // ctor ----------------------------------------------------------------- - SBotChatAutomatonState(SBotChatPage *page,uint on0=std::numeric_limits::max(),uint on1=std::numeric_limits::max(),uint on2=std::numeric_limits::max(),uint on3=std::numeric_limits::max(),uint on4=std::numeric_limits::max()) - { - Page=page; - On[0]=on0; - On[1]=on1; - On[2]=on2; - On[3]=on3; - On[4]=on4; - - // make sure the number of arguments supplied corresponds to the - // number of options prresent on the user interfac page - nlassert(page->NumOptions>=0 && page->NumOptions<=4); - nlassert(page->NumOptions==0 || On[page->NumOptions-1]!=std::numeric_limits::max()); - nlassert(page->NumOptions==4 || On[page->NumOptions]==std::numeric_limits::max()); - } -}; - - -////////////////////////////////////////////////////////////////////////////// -// the structure for a bot chat automatons & a singleton for indexing -// automatons by name - -struct SBotChatAutomaton -{ - // public data ---------------------------------------------------------- - string Name; - SBotChatAutomatonState *States; - uint Size; - - // ctor ----------------------------------------------------------------- - SBotChatAutomaton(string name, SBotChatAutomatonState *states,uint size) - { - Name=name; - States=states; - Size=size; - - if (NameMap.find(name)!=NameMap.end()) - { - nlwarning("SBotChatAutomaton::SBotChatAutomaton(): More than one instance with name: %s",name.c_str()); - return; - } - NameMap[name]=this; - } - - // dtor ----------------------------------------------------------------- - ~SBotChatAutomaton() - { - map ::iterator it=NameMap.find(Name); - if (it!=NameMap.end() && (*it).second==this) - NameMap.erase(it); - // don't try to display a warning in a dtor as the warning system is - // probably already down - } - - - // singleton methods ---------------------------------------------------- - static SBotChatAutomaton *getAutomatonByName(string name) - { - map ::iterator it=NameMap.find(name); - if (it==NameMap.end()) - return NULL; - return (*it).second; - } - - // singleton data ------------------------------------------------------- - static map NameMap; -}; -map SBotChatAutomaton::NameMap; - - -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -// Implementation of different code modules for handling different bot -// chat page types - -////////////////////////////////////////////////////////////////////////////// -// this is a dummy page used to terminate chats - -class CBotChatPageTypeDone: public CBotChatPageType -{ -public: - virtual bool open(const CEntityId &player, const CEntityId &bot) - { - return false; // stop the bot chat! - } - - virtual bool close(const CEntityId &player, const CEntityId &bot) - { - return false; - } -} -BotChatPageTypeDone; - - -////////////////////////////////////////////////////////////////////////////// -// definition for a chat page that contains static text and buttons for -// player to click on/ select - -class CBotChatPageTypeTextOnly: public CBotChatPageType -{ -public: - virtual bool open(const CEntityId &player, const CEntityId &bot) - { - return true; - } - - virtual bool close(const CEntityId &player, const CEntityId &bot) - { - return true; - } -} -BotChatPageTypeTextOnly; - - -////////////////////////////////////////////////////////////////////////////// -// definition for a chat page that displays NEWS as well as other text - -class CBotChatPageTypeNews: public CBotChatPageType -{ -public: - virtual bool open(const CEntityId &player, const CEntityId &bot) - { - return true; - } - - virtual bool close(const CEntityId &player, const CEntityId &bot) - { - return true; - } -} -BotChatPageTypeNews; - - -////////////////////////////////////////////////////////////////////////////// -// definition for a chat page that displays a SHOP interface - -class CBotChatPageTypeShop: public CBotChatPageType -{ -public: - virtual bool open(const CEntityId &player, const CEntityId &bot) - { - nlinfo ("player %s entered trade page", player.toString().c_str()); - CMessage msgout( "TRADE_BEGIN" ); - msgout.serial( const_cast(player) ); - msgout.serial( const_cast(bot) ); - sendMessageViaMirror( "WOS", msgout ); - return true; - } - - virtual bool close(const CEntityId &player, const CEntityId &bot) - { - nlinfo ("end of trade with player %s", player.toString().c_str()); - CMessage msgout( "TRADE_END" ); - msgout.serial( const_cast(player) ); - msgout.serial( const_cast(bot) ); - sendMessageViaMirror( "WOS", msgout ); - sendMessageViaMirror( "EGS", msgout ); - return true; - } -} -BotChatPageTypeShop; - - -////////////////////////////////////////////////////////////////////////////// -// definition for a chat page that displays a MISSION SHOP interface - -class CBotChatPageTypeMissionShop: public CBotChatPageType -{ -public: - virtual bool open(const CEntityId &player, const CEntityId &bot) - { - nlinfo ("player %s entered mission page", player.toString().c_str()); - CMessage msgout( "MISSION_LIST_BEGIN" ); - msgout.serial( const_cast(player) ); - msgout.serial( const_cast(bot) ); - sendMessageViaMirror( "WOS", msgout ); - return true; - } - - virtual bool close(const CEntityId &player, const CEntityId &bot) - { - nlinfo ("end of mission page with player %s", player.toString().c_str()); - CMessage msgout( "MISSION_LIST_END" ); - msgout.serial( const_cast(player) ); - msgout.serial( const_cast(bot) ); - sendMessageViaMirror( "EGS", msgout ); - return true; - } -} -BotChatPageTypeMissionShop; - - - -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -// Definitions of bot chat pages and automatons - -// define the usable bot chat pages ------------------------------------------ -SBotChatPage BotChatPageIntro (BOTCHATTYPE::Intro, &BotChatPageTypeTextOnly, 4); -SBotChatPage BotChatPageFriendly (BOTCHATTYPE::FriendlyMainPage, &BotChatPageTypeNews, 4); -SBotChatPage BotChatPageNeutral (BOTCHATTYPE::NeutralMainPage, &BotChatPageTypeNews, 3); -SBotChatPage BotChatPageHostile (BOTCHATTYPE::NastyMainPage, &BotChatPageTypeTextOnly, 1); -SBotChatPage BotChatPageMoreNews (BOTCHATTYPE::MoreNewsPage, &BotChatPageTypeNews, 2); -SBotChatPage BotChatPageShop (BOTCHATTYPE::BuySellPage, &BotChatPageTypeShop, 2); -SBotChatPage BotChatPageMissionShop (BOTCHATTYPE::MissionsPage, &BotChatPageTypeMissionShop, 2); -SBotChatPage BotChatPageDone (BOTCHATTYPE::Done, &BotChatPageTypeDone, 0); - -// the default automaton ----------------------------------------------------- -SBotChatAutomatonState BotChatStatesDefault[]= -{ - SBotChatAutomatonState(&BotChatPageIntro,2,3,4,1), // 0 - friendly/ neutral/ hostile/ done - SBotChatAutomatonState(&BotChatPageDone), // 1 - SBotChatAutomatonState(&BotChatPageFriendly,5,6,7,1), // 2 - more news/ buy sell/ mission/ done - SBotChatAutomatonState(&BotChatPageNeutral,6,7,1), // 3 - buy sell/ mission/ done - SBotChatAutomatonState(&BotChatPageHostile,1), // 4 - done - SBotChatAutomatonState(&BotChatPageMoreNews,2,1), // 5 - friendly/ done - SBotChatAutomatonState(&BotChatPageShop,3,1), // 6 - neutral/ done - SBotChatAutomatonState(&BotChatPageMissionShop,3,1), // 7 - neutral/ done -}; -SBotChatAutomaton BotChatDefault("default",BotChatStatesDefault,sizeof(BotChatStatesDefault)/sizeof(BotChatStatesDefault[0])); - -// the automaton for merchants ----------------------------------------------- -SBotChatAutomatonState BotChatStatesMerchant[]= -{ - SBotChatAutomatonState(&BotChatPageMoreNews,2,1), // 0 - shop/ done - SBotChatAutomatonState(&BotChatPageDone), // 1 - SBotChatAutomatonState(&BotChatPageShop,0,1), // 2 - news/ done -}; -SBotChatAutomaton BotChatMerchant("merchant",BotChatStatesMerchant,sizeof(BotChatStatesMerchant)/sizeof(BotChatStatesMerchant[0])); - -// the automaton for walkers and talkers ------------------------------------- -SBotChatAutomatonState BotChatStatesWalkerTalker[]= -{ - SBotChatAutomatonState(&BotChatPageHostile,1), // 0 - SBotChatAutomatonState(&BotChatPageDone) // 1 -}; -SBotChatAutomaton BotChatWalkerTalker("walker talker",BotChatStatesWalkerTalker,sizeof(BotChatStatesMerchant)/sizeof(BotChatStatesMerchant[0])); - - -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -// Represetnation of a conversation between a player and a bot -// includes conversation automaton state data - -struct CBotChat -{ - CBotChat () : Player(CEntityId::Unknown), Bot(CEntityId::Unknown) { } - CBotChat (CEntityId player, CEntityId bot, SBotChatAutomaton *automaton) - { - Player=player; - Bot=bot; - setAutomaton(automaton); - } - - void setState(uint32 state) - { - if (state>=Automaton->Size && state!=std::numeric_limits::max()) - { - nlwarning("CBotChatEntry()::setState: Invalid state: %d",state); - return; - } - - // if there is already a page open close it - if (CurrentStateSize) - Automaton->States[CurrentState].Page->PageType->close(Player,Bot); - - // open the new page - CurrentState=state; - if (state==std::numeric_limits::max()) - Done=true; - else - Done=!Automaton->States[CurrentState].Page->PageType->open(Player,Bot); - - // transmit the new page id to the client - uint32 happyness=10; - BOTCHATTYPE::TBotChatInterfaceId interfaceId=Done?BOTCHATTYPE::Done:Automaton->States[CurrentState].Page->ClientInterfaceId; - NEWSTYPE::TNewsType newsType=NEWSTYPE::Unknown; - - CMessage msgout("BOT_CHAT_SELECT_INTERFACE"); - msgout.serial (Player); - msgout.serial (happyness); - msgout.serialEnum (interfaceId); - msgout.serialEnum (newsType); - sendMessageViaMirror("IOS", msgout); - } - - void setAutomaton(SBotChatAutomaton *automaton) - { - Automaton=automaton; - CurrentState=std::numeric_limits::max(); // set this to a std::numeric_limits::max() so that setState doesn't try to clse existing page - setState(0); - } - - void selectEntry (sint8 userInput) - { - // select the new page - if ((unsigned)userInput >= Automaton->States[CurrentState].Page->NumOptions) - { - nlwarning ("CBotChatEntry::selectEntry: For player %s: input out of bounds: %d", Player.toString().c_str(), userInput); - return; - } - - // advance through the state table - setState(Automaton->States[CurrentState].On[userInput]); - } - - void endChat () - { - setState(std::numeric_limits::max()); - } - - CEntityId Player; - CEntityId Bot; - SBotChatAutomaton *Automaton; - uint32 CurrentState; - bool Done; -}; - - -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -// Singleton manager class central to the bot chat system - -class CBotChatManager -{ -public: - - static void newChat(CEntityId player, CEntityId bot) - { - // make sure the player isn't already chatting - map::iterator it = BotChatMap.find (player); - if (it != BotChatMap.end()) - return; - - // a bit of logging - nlinfo ("new chat between player %s and bot %s", player.toString().c_str(), bot.toString().c_str()); - - // call the CbBegin() callback to get the name of the automaton to use - string automatonName; - if (CbBegin!=NULL) - automatonName=CbBegin(player,bot); - else - automatonName="default"; - SBotChatAutomaton *automaton=SBotChatAutomaton::getAutomatonByName(automatonName); - if (automaton==NULL) - { - nlwarning("- ignoring bot chat request as automaton '%s' not found",automatonName.c_str()); - return; - } - - // setup the new chat - BotChatMap[player] = CBotChat(player, bot, automaton); - } - - static void endChat(CEntityId player) - { - CEntityId bot; // for use in callback ... at end of routine - - map::iterator it = BotChatMap.find (player); - if (it != BotChatMap.end()) - { - bot=(*it).second.Bot; - - nlinfo ("end of bot chat between player %s and bot %s", player.toString().c_str(),bot.toString().c_str()); - - // if the chat is still active then stop it - if ((*it).second.Done) - (*it).second.endChat(); - - // remove the map entry - BotChatMap.erase (it); - - // **** this code may be dodgy 'cos its in a dtor - // **** if it is dodgy then we need to migrate from an STL map - // **** to some kind of custom structure that we can guarantee OK - } - - if (CbEnd!=NULL) - CbEnd(player,bot); - } - - static void treatInput(CEntityId player, sint8 userInput) - { - // locate the bot chat for the given player - map::iterator it = BotChatMap.find (player); - if (it == BotChatMap.end()) - { - nlwarning ("No bot chat with the player %s", player.toString().c_str()); - return; - } - - // pass the player input to the bot chat handler - (*it).second.selectEntry(userInput); - - // check whether the bot chat is finished - if ((*it).second.Done) - endChat(player); - } - - - // static data for the singleton ----------------------------------------- - static CBotChatInterface::TCallbackBegin CbBegin; - static CBotChatInterface::TCallbackEnd CbEnd; - static map BotChatMap; -}; -CBotChatInterface::TCallbackBegin CBotChatManager::CbBegin; -CBotChatInterface::TCallbackEnd CBotChatManager::CbEnd; -map CBotChatManager::BotChatMap; - - -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -// message callbacks and callback table - -static void cbBotChatStart (CMessage& msgin, const string &serviceName, uint16 serviceId ) -{ - CEntityId player, bot; - - msgin.serial( player ); - msgin.serial( bot ); - - CBotChatManager::newChat (player, bot); -} - -static void cbBotChatSelectAnswer (CMessage& msgin, const string &serviceName, uint16 serviceId ) -{ - CEntityId player, bot; - sint8 answer; - - msgin.serial( player ); - msgin.serial( answer ); - - CBotChatManager::treatInput (player, answer); -} - - -static TUnifiedCallbackItem CbArray[]= -{ - { "BOT_CHAT_START", cbBotChatStart }, - { "BOT_CHAT_SELECT_ANSWER", cbBotChatSelectAnswer }, -}; - - -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -// Interface class providing API for bot chat system - -void CBotChatInterface::init(CBotChatInterface::TCallbackBegin cbBegin,CBotChatInterface::TCallbackEnd cbEnd) -{ - CBotChatManager::CbBegin=cbBegin; - CBotChatManager::CbEnd=cbEnd; - CUnifiedNetwork::getInstance()->addCallbackArray(CbArray, sizeof (CbArray) / sizeof (CbArray[0])); -} - -void CBotChatInterface::release() -{ -} - -void CBotChatInterface::getBotChatPartners(CEntityId bot,vector &result) -{ - map::iterator it; - for (it=CBotChatManager::BotChatMap.begin();it!=CBotChatManager::BotChatMap.end();++it) - if ((*it).second.Bot==bot) - result.push_back((*it).first); -} - -void CBotChatInterface::endChatForPlayer(CEntityId player) -{ - CBotChatManager::endChat(player); -} - -void CBotChatInterface::endAllChatForBot(CEntityId bot) -{ - map::iterator it=CBotChatManager::BotChatMap.begin(); - while (it!=CBotChatManager::BotChatMap.end()) - { - map::iterator next=it; - if ((*it).second.Bot==bot) - CBotChatManager::endChat((*it).first); - it=next; - } -} - -#endif - -#endif diff --git a/code/ryzom/server/src/ai_service/bot_chat_interface.h b/code/ryzom/server/src/ai_service/bot_chat_interface.h deleted file mode 100644 index 3586b737f..000000000 --- a/code/ryzom/server/src/ai_service/bot_chat_interface.h +++ /dev/null @@ -1,58 +0,0 @@ -// Ryzom - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero 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 Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - - -#error "Deprecated" - -#ifndef RYAI_BOT_CHAT_INTERFACE_H -#define RYAI_BOT_CHAT_INTERFACE_H - -// Nel Misc -#include "nel/misc/types_nl.h" -#include "nel/misc/entity_id.h" -#include "game_share/news_types.h" -#include "game_share/bot_chat_types.h" - -// the class -class CBotChatInterface -{ -public: - // the callback type for user callbacks for start of bot chat - // returns the name of the bot chat automaton to use - // if an empty string is returned no bot chat is launched - typedef std::string (*TCallbackBegin)(NLMISC::CEntityId player,NLMISC::CEntityId bot); - - // the callback types for user callback for end of bot chat - // called just after the chat session has been closed - typedef void (*TCallbackEnd)(NLMISC::CEntityId player,NLMISC::CEntityId bot); - -public: - // classic init() and release() - static void init(TCallbackBegin cbBegin=NULL,TCallbackEnd cbEnd=NULL); - static void release(); - - // build a vector of the players currently chatting with a given bot - // this routine may not be very fast as the entire bot chat map is - // parsed in order to build the vector - static void getBotChatPartners(NLMISC::CEntityId bot,std::vector &result); - - // routines to force the end of a bot chat - static void endChatForPlayer(NLMISC::CEntityId player); - static void endAllChatForBot(NLMISC::CEntityId bot); -}; - -#endif diff --git a/code/ryzom/server/src/input_output_service/input_output_service.cpp b/code/ryzom/server/src/input_output_service/input_output_service.cpp index de3d73458..f2cd67d22 100644 --- a/code/ryzom/server/src/input_output_service/input_output_service.cpp +++ b/code/ryzom/server/src/input_output_service/input_output_service.cpp @@ -21,7 +21,6 @@ #include "game_share/tick_event_handler.h" #include "game_share/msg_client_server.h" #include "game_share/mode_and_behaviour.h" //TEMP!!! -#include "game_share/news_types.h" #include "game_share/bot_chat_types.h" #include "game_share/brick_types.h" #include "game_share/loot_harvest_state.h" @@ -35,7 +34,6 @@ #include "nel/misc/command.h" #include "nel/net/message.h" -#include "news_manager.h" #include "string_manager.h" #include "messages.h" //#include "ios_pd.h" diff --git a/code/ryzom/server/src/input_output_service/news_manager.cpp b/code/ryzom/server/src/input_output_service/news_manager.cpp deleted file mode 100644 index b8b093c99..000000000 --- a/code/ryzom/server/src/input_output_service/news_manager.cpp +++ /dev/null @@ -1,83 +0,0 @@ -// Ryzom - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero 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 Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - -#include "stdpch.h" -#include "news_manager.h" -#include "input_output_service.h" - -//#include "game_share/generic_msg_mngr.h" -#include "game_share/msg_client_server.h" -#include "game_share/news_types.h" - -using namespace std; -using namespace NLMISC; -using namespace NLNET; - -class CNewsEntry -{ -public: - CNewsEntry () : Type(NEWSTYPE::Unknown) { } - CNewsEntry (NEWSTYPE::TNewsType type, const string &stringId, const vector &args) : Type(type), StringId(StringId), Args(args) { } - - NEWSTYPE::TNewsType Type; - string StringId; - vector Args; -}; - -deque News; - -static void cbAddNews (CMessage& msgin, const std::string &serviceName, TServiceId serviceId ) -{ - NEWSTYPE::TNewsType type = NEWSTYPE::Unknown; - string stringId; - vector args; - - msgin.serialEnum (type); - msgin.serial (stringId); - msgin.serialCont (args); - - News.push_back(CNewsEntry(type, stringId, args)); - - nlinfo ("added news %s for type %d from service %s", stringId.c_str(), type, serviceName.c_str()); -} - - -static TUnifiedCallbackItem CbArray[]= -{ - { "ADD_NEWS", cbAddNews }, -}; - - -void CNewsManager::init() -{ - CUnifiedNetwork::getInstance()->addCallbackArray(CbArray, sizeof (CbArray) / sizeof (CbArray[0])); -} - - -void CNewsManager::getNews (NEWSTYPE::TNewsType type, CBitMemStream &bms) -{ - nlassert (type != NEWSTYPE::Unknown); - - sint val = (sint)frand ((float)News.size()); - - string res; - //CChatManager::getStaticDB ().getInfos (News[val].stringId, res, bms); - nlinfo ("sending news '%s' '%s' with %d args", News[val].StringId.c_str(), res.c_str(), News[val].Args.size()); - - //bms.serial (News[val].stringId); - bms.serialCont (News[val].Args); -} diff --git a/code/ryzom/server/src/input_output_service/news_manager.h b/code/ryzom/server/src/input_output_service/news_manager.h deleted file mode 100644 index dee34e5be..000000000 --- a/code/ryzom/server/src/input_output_service/news_manager.h +++ /dev/null @@ -1,60 +0,0 @@ -// Ryzom - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero 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 Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - - -#ifndef NEWS_MANAGER_H -#define NEWS_MANAGER_H - - -// misc -#include "nel/misc/types_nl.h" -#include "nel/misc/bit_mem_stream.h" - -// game share -#include "game_share/ryzom_entity_id.h" -//#include "game_share/chat_static_database.h" -//#include "game_share/chat_dynamic_database.h" -#include "game_share/news_types.h" - -// std -#include -#include - - -/** - * CNewsManager - * \author Vianney Lecroart - * \author Nevrax France - * \date 2002 - */ -class CNewsManager -{ -public : - - /** - * Init the manager. - */ - static void init (); - - /// return a news of a given type - static void getNews (NEWSTYPE::TNewsType type, NLMISC::CBitMemStream &bms); -}; - - -#endif // NEWS_MANAGER_H - -/* End of news_manager.h */ diff --git a/code/ryzom/server/src/input_output_service/stdpch.h b/code/ryzom/server/src/input_output_service/stdpch.h index 17f5e6bc5..67599f732 100644 --- a/code/ryzom/server/src/input_output_service/stdpch.h +++ b/code/ryzom/server/src/input_output_service/stdpch.h @@ -74,7 +74,6 @@ #include "game_share/mirror_prop_value.h" #include "game_share/mode_and_behaviour.h" #include "game_share/msg_client_server.h" -#include "game_share/news_types.h" #include "game_share/people.h" #include "game_share/player_visual_properties.h" #include "game_share/power_types.h"