PageRenderTime 28ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/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
Possible License(s): LGPL-2.1
  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. #include "llviewerprecompiledheaders.h"
  29. #include "llnearbychatbarlistener.h"
  30. #include "llnearbychatbar.h"
  31. #include "llagent.h"
  32. #include "llchat.h"
  33. LLNearbyChatBarListener::LLNearbyChatBarListener(LLNearbyChatBar & chatbar)
  34. : LLEventAPI("LLChatBar",
  35. "LLChatBar listener to (e.g.) sendChat, etc."),
  36. mChatbar(chatbar)
  37. {
  38. add("sendChat",
  39. "Send chat to the simulator:\n"
  40. "[\"message\"] chat message text [required]\n"
  41. "[\"channel\"] chat channel number [default = 0]\n"
  42. "[\"type\"] chat type \"whisper\", \"normal\", \"shout\" [default = \"normal\"]",
  43. &LLNearbyChatBarListener::sendChat);
  44. }
  45. // "sendChat" command
  46. void LLNearbyChatBarListener::sendChat(LLSD const & chat_data) const
  47. {
  48. // Extract the data
  49. std::string chat_text = chat_data["message"].asString();
  50. S32 channel = 0;
  51. if (chat_data.has("channel"))
  52. {
  53. channel = chat_data["channel"].asInteger();
  54. if (channel < 0 || channel >= CHAT_CHANNEL_DEBUG)
  55. { // Use 0 up to (but not including) CHAT_CHANNEL_DEBUG
  56. channel = 0;
  57. }
  58. }
  59. EChatType type_o_chat = CHAT_TYPE_NORMAL;
  60. if (chat_data.has("type"))
  61. {
  62. std::string type_string = chat_data["type"].asString();
  63. if (type_string == "whisper")
  64. {
  65. type_o_chat = CHAT_TYPE_WHISPER;
  66. }
  67. else if (type_string == "shout")
  68. {
  69. type_o_chat = CHAT_TYPE_SHOUT;
  70. }
  71. }
  72. // Have to prepend /42 style channel numbers
  73. std::string chat_to_send;
  74. if (channel == 0)
  75. {
  76. chat_to_send = chat_text;
  77. }
  78. else
  79. {
  80. chat_to_send += "/";
  81. chat_to_send += chat_data["channel"].asString();
  82. chat_to_send += " ";
  83. chat_to_send += chat_text;
  84. }
  85. // Send it as if it was typed in
  86. mChatbar.sendChatFromViewer(chat_to_send, type_o_chat, (BOOL)(channel == 0));
  87. }