PageRenderTime 22ms CodeModel.GetById 13ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llnearbychatbarlistener.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 100 lines | 56 code | 13 blank | 31 comment | 12 complexity | fc48cb21f61e11f0040ca53c2a4ec4c1 MD5 | raw file
  1/**
  2 * @file   llnearbychatbarlistener.cpp
  3 * @author Dave Simmons
  4 * @date   2011-03-15
  5 * @brief  Implementation for LLNearbyChatBarListener.
  6 *
  7 * $LicenseInfo:firstyear=2011&license=viewerlgpl$
  8 * Second Life Viewer Source Code
  9 * Copyright (C) 2011, Linden Research, Inc.
 10 *
 11 * This library is free software; you can redistribute it and/or
 12 * modify it under the terms of the GNU Lesser General Public
 13 * License as published by the Free Software Foundation;
 14 * version 2.1 of the License only.
 15 *
 16 * This library is distributed in the hope that it will be useful,
 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 19 * Lesser General Public License for more details.
 20 *
 21 * You should have received a copy of the GNU Lesser General Public
 22 * License along with this library; if not, write to the Free Software
 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 24 *
 25 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 26 * $/LicenseInfo$
 27 */
 28
 29#include "llviewerprecompiledheaders.h"
 30
 31#include "llnearbychatbarlistener.h"
 32#include "llnearbychatbar.h"
 33
 34#include "llagent.h"
 35#include "llchat.h"
 36
 37
 38
 39LLNearbyChatBarListener::LLNearbyChatBarListener(LLNearbyChatBar & chatbar)
 40  : LLEventAPI("LLChatBar",
 41               "LLChatBar listener to (e.g.) sendChat, etc."),
 42	mChatbar(chatbar)
 43{
 44    add("sendChat",
 45        "Send chat to the simulator:\n"
 46        "[\"message\"] chat message text [required]\n"
 47        "[\"channel\"] chat channel number [default = 0]\n"
 48		"[\"type\"] chat type \"whisper\", \"normal\", \"shout\" [default = \"normal\"]",
 49        &LLNearbyChatBarListener::sendChat);
 50}
 51
 52
 53// "sendChat" command
 54void LLNearbyChatBarListener::sendChat(LLSD const & chat_data) const
 55{
 56	// Extract the data
 57	std::string chat_text = chat_data["message"].asString();
 58
 59	S32 channel = 0;
 60	if (chat_data.has("channel"))
 61	{
 62		channel = chat_data["channel"].asInteger();
 63		if (channel < 0 || channel >= CHAT_CHANNEL_DEBUG)
 64		{	// Use 0 up to (but not including) CHAT_CHANNEL_DEBUG
 65			channel = 0;
 66		}
 67	}
 68
 69	EChatType type_o_chat = CHAT_TYPE_NORMAL;
 70	if (chat_data.has("type"))
 71	{
 72		std::string type_string = chat_data["type"].asString();
 73		if (type_string == "whisper")
 74		{
 75			type_o_chat = CHAT_TYPE_WHISPER;
 76		}
 77		else if (type_string == "shout")
 78		{
 79			type_o_chat = CHAT_TYPE_SHOUT;
 80		}
 81	}
 82
 83	// Have to prepend /42 style channel numbers
 84	std::string chat_to_send;
 85	if (channel == 0)
 86	{
 87		chat_to_send = chat_text;
 88	}
 89	else
 90	{
 91		chat_to_send += "/";
 92		chat_to_send += chat_data["channel"].asString();
 93		chat_to_send += " ";
 94		chat_to_send += chat_text;
 95	}
 96
 97	// Send it as if it was typed in
 98	mChatbar.sendChatFromViewer(chat_to_send, type_o_chat, (BOOL)(channel == 0));
 99}
100