// 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
//#include "game_share/generic_msg_mngr.h"
#include "game_share/msg_client_server.h"
#include "game_share/synchronised_message.h"
#include "game_share/ryzom_entity_id.h"
#include "game_share/properties.h"
#include "game_share/backup_service_interface.h"
#include "server_share/r2_variables.h"
#include "chat_manager.h"
#include "input_output_service.h"
#include "chat_unifier_client.h"
#include "server_share/log_chat_gen.h"
//#include "ios_pd.h"
using namespace std;
using namespace NLMISC;
using namespace NLNET;
void logChatDirChanged(IVariable &var)
{
// LogChatDirectory variable changed, reset it!
//IOS->getChatManager().resetChatLog();
}
CVariable VerboseChatManagement("ios","VerboseChatManagement", "Set verbosity for chat management", false, 0, true);
CVariable LogChatDirectory("ios", "LogChatDirectory", "Log Chat directory (default, unset is SaveFiles service directory", "", 0, true, logChatDirChanged);
CVariable ForceFarChat("ios","ForceFarChat", "Force the use of SU to dispatch chat", false, 0, true);
CChatManager::CChatManager () : _Log(CLog::LOG_INFO)
{
_Log.addDisplayer(&_Displayer);
}
//-----------------------------------------------
// init
//
//-----------------------------------------------
void CChatManager::init( /*const string& staticDBFileName, const string& dynDBFileName*/ )
{
// if (!staticDBFileName.empty())
// _StaticDB.load( staticDBFileName );
//
// if (!dynDBFileName.empty())
// _DynDB.load( dynDBFileName );
// create a chat group 'universe'
addGroup(CEntityId(RYZOMID::chatGroup,0), CChatGroup::universe, "");
// reset chat log system (at least to init it once!)
resetChatLog();
} // init //
void CChatManager::onServiceDown(const std::string &serviceShortName)
{
// if service is EGS, remove all chat groups
if (serviceShortName == "EGS")
{
vector groupToRemove;
// parse all group, selecting the one to remove when ESG is down
std::map< TGroupId, CChatGroup >::iterator first(_Groups.begin()), last(_Groups.end());
for (; first != last; ++first)
{
const TGroupId &gid = first->first;
const CChatGroup &cg = first->second;
switch (cg.Type)
{
case CChatGroup::universe:
case CChatGroup::say:
case CChatGroup::shout:
continue;
case CChatGroup::team:
case CChatGroup::guild:
case CChatGroup::civilization:
case CChatGroup::territory:
case CChatGroup::tell:
case CChatGroup::arround:
case CChatGroup::system:
case CChatGroup::region:
case CChatGroup::dyn_chat:
groupToRemove.push_back(gid);
break;
}
}
// remove all chat groups that belong to EGS or players
for (uint i=0; isecond->unsubscribeAllChatGroup();
delete itCl->second;
_Clients.erase( itCl );
}
else
{
nlwarning("CChatManager::removeClient : The client %s:%x is unknown !",
TheDataset.getEntityId(id).toString().c_str(),
id.getIndex());
}
// remove from the dyn chat
_DynChat.removeClient(id);
} // removeClient //
//-----------------------------------------------
// getClient
//
//-----------------------------------------------
CChatClient& CChatManager::getClient( const TDataSetRow& id )
{
TClientInfoCont::iterator itCl = _Clients.find( id );
if( itCl != _Clients.end() )
{
return *(itCl->second);
}
else
{
throw CChatManager::EChatClient(TheDataset.getEntityId(id));
}
} // getClient //
//-----------------------------------------------
// addGroup
//
//-----------------------------------------------
void CChatManager::addGroup( TGroupId gId, CChatGroup::TGroupType gType, const std::string &groupName )
{
if ( gId == CEntityId::Unknown )
{
nlwarning(" Cannot add chat group CEntityId::Unknown. group name = '%s'",groupName.c_str());
return;
}
if (VerboseChatManagement)
{
if (!groupName.empty())
nldebug("IOSCM: addGroup : adding %s named chat group %s as '%s'",
CChatGroup::groupTypeToString(gType).c_str(),
gId.toString().c_str(),
groupName.c_str());
else
nldebug("IOSCM: addGroup : adding %s anonymous chat group %s",
CChatGroup::groupTypeToString(gType).c_str(),
gId.toString().c_str());
}
map< TGroupId, CChatGroup >::iterator itGrp = _Groups.find( gId );
if( itGrp == _Groups.end() )
{
TStringId nameId = CStringMapper::map(groupName);
_Groups.insert( make_pair(gId, CChatGroup(gType, nameId)) );
if (!groupName.empty())
{
pair