llgroupactions.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:9k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llgroupactions.cpp
  3.  * @brief Group-related actions (join, leave, new, delete, etc)
  4.  *
  5.  * $LicenseInfo:firstyear=2009&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2009-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llgroupactions.h"
  34. #include "message.h"
  35. #include "llagent.h"
  36. #include "llcommandhandler.h"
  37. #include "llfloaterreg.h"
  38. #include "llgroupmgr.h"
  39. #include "llimview.h" // for gIMMgr
  40. #include "llnotificationsutil.h"
  41. #include "llsidetray.h"
  42. #include "llstatusbar.h" // can_afford_transaction()
  43. #include "llimfloater.h"
  44. //
  45. // Globals
  46. //
  47. class LLGroupHandler : public LLCommandHandler
  48. {
  49. public:
  50. // requires trusted browser to trigger
  51. LLGroupHandler() : LLCommandHandler("group", UNTRUSTED_THROTTLE) { }
  52. bool handle(const LLSD& tokens, const LLSD& query_map,
  53. LLMediaCtrl* web)
  54. {
  55. if (tokens.size() < 1)
  56. {
  57. return false;
  58. }
  59. if (tokens[0].asString() == "create")
  60. {
  61. LLGroupActions::createGroup();
  62. return true;
  63. }
  64. if (tokens.size() < 2)
  65. {
  66. return false;
  67. }
  68. //*TODO by what to replace showing groups floater?
  69. if (tokens[0].asString() == "list")
  70. {
  71. if (tokens[1].asString() == "show")
  72. {
  73. //LLFloaterReg::showInstance("contacts", "groups");
  74. return true;
  75. }
  76.             return false;
  77. }
  78. LLUUID group_id;
  79. if (!group_id.set(tokens[0], FALSE))
  80. {
  81. return false;
  82. }
  83. if (tokens[1].asString() == "about")
  84. {
  85. if (group_id.isNull())
  86. return true;
  87. LLGroupActions::show(group_id);
  88. return true;
  89. }
  90. if (tokens[1].asString() == "inspect")
  91. {
  92. if (group_id.isNull())
  93. return true;
  94. LLGroupActions::show(group_id);
  95. return true;
  96. }
  97. return false;
  98. }
  99. };
  100. LLGroupHandler gGroupHandler;
  101. // static
  102. void LLGroupActions::search()
  103. {
  104. LLFloaterReg::showInstance("search", LLSD().with("category", "groups"));
  105. }
  106. // static
  107. void LLGroupActions::startCall(const LLUUID& group_id)
  108. {
  109. // create a new group voice session
  110. LLGroupData gdata;
  111. if (!gAgent.getGroupData(group_id, gdata))
  112. {
  113. llwarns << "Error getting group data" << llendl;
  114. return;
  115. }
  116. LLUUID session_id = gIMMgr->addSession(gdata.mName, IM_SESSION_GROUP_START, group_id, true);
  117. if (session_id == LLUUID::null)
  118. {
  119. llwarns << "Error adding session" << llendl;
  120. return;
  121. }
  122. // start the call
  123. gIMMgr->autoStartCallOnStartup(session_id);
  124. make_ui_sound("UISndStartIM");
  125. }
  126. // static
  127. void LLGroupActions::join(const LLUUID& group_id)
  128. {
  129. if (!gAgent.canJoinGroups())
  130. {
  131. LLNotificationsUtil::add("JoinedTooManyGroups");
  132. return;
  133. }
  134. LLGroupMgrGroupData* gdatap = 
  135. LLGroupMgr::getInstance()->getGroupData(group_id);
  136. if (gdatap)
  137. {
  138. S32 cost = gdatap->mMembershipFee;
  139. LLSD args;
  140. args["COST"] = llformat("%d", cost);
  141. args["NAME"] = gdatap->mName;
  142. LLSD payload;
  143. payload["group_id"] = group_id;
  144. if (can_afford_transaction(cost))
  145. {
  146. if(cost > 0)
  147. LLNotificationsUtil::add("JoinGroupCanAfford", args, payload, onJoinGroup);
  148. else
  149. LLNotificationsUtil::add("JoinGroupNoCost", args, payload, onJoinGroup);
  150. }
  151. else
  152. {
  153. LLNotificationsUtil::add("JoinGroupCannotAfford", args, payload);
  154. }
  155. }
  156. else
  157. {
  158. llwarns << "LLGroupMgr::getInstance()->getGroupData(" << group_id 
  159. << ") was NULL" << llendl;
  160. }
  161. }
  162. // static
  163. bool LLGroupActions::onJoinGroup(const LLSD& notification, const LLSD& response)
  164. {
  165. S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
  166. if (option == 1)
  167. {
  168. // user clicked cancel
  169. return false;
  170. }
  171. LLGroupMgr::getInstance()->
  172. sendGroupMemberJoin(notification["payload"]["group_id"].asUUID());
  173. return false;
  174. }
  175. // static
  176. void LLGroupActions::leave(const LLUUID& group_id)
  177. {
  178. if (group_id.isNull())
  179. return;
  180. S32 count = gAgent.mGroups.count();
  181. S32 i;
  182. for (i = 0; i < count; ++i)
  183. {
  184. if(gAgent.mGroups.get(i).mID == group_id)
  185. break;
  186. }
  187. if (i < count)
  188. {
  189. LLSD args;
  190. args["GROUP"] = gAgent.mGroups.get(i).mName;
  191. LLSD payload;
  192. payload["group_id"] = group_id;
  193. LLNotificationsUtil::add("GroupLeaveConfirmMember", args, payload, onLeaveGroup);
  194. }
  195. }
  196. // static
  197. void LLGroupActions::activate(const LLUUID& group_id)
  198. {
  199. LLMessageSystem* msg = gMessageSystem;
  200. msg->newMessageFast(_PREHASH_ActivateGroup);
  201. msg->nextBlockFast(_PREHASH_AgentData);
  202. msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  203. msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  204. msg->addUUIDFast(_PREHASH_GroupID, group_id);
  205. gAgent.sendReliableMessage();
  206. }
  207. static bool isGroupUIVisible()
  208. {
  209. static LLPanel* panel = 0;
  210. if(!panel)
  211. panel = LLSideTray::getInstance()->findChild<LLPanel>("panel_group_info_sidetray");
  212. if(!panel)
  213. return false;
  214. return panel->isInVisibleChain();
  215. }
  216. // static
  217. void LLGroupActions::show(const LLUUID& group_id)
  218. {
  219. if (group_id.isNull())
  220. return;
  221. LLSD params;
  222. params["group_id"] = group_id;
  223. params["open_tab_name"] = "panel_group_info_sidetray";
  224. LLSideTray::getInstance()->showPanel("panel_group_info_sidetray", params);
  225. }
  226. void LLGroupActions::refresh_notices()
  227. {
  228. if(!isGroupUIVisible())
  229. return;
  230. LLSD params;
  231. params["group_id"] = LLUUID::null;
  232. params["open_tab_name"] = "panel_group_info_sidetray";
  233. params["action"] = "refresh_notices";
  234. LLSideTray::getInstance()->showPanel("panel_group_info_sidetray", params);
  235. }
  236. //static 
  237. void LLGroupActions::refresh(const LLUUID& group_id)
  238. {
  239. if(!isGroupUIVisible())
  240. return;
  241. LLSD params;
  242. params["group_id"] = group_id;
  243. params["open_tab_name"] = "panel_group_info_sidetray";
  244. params["action"] = "refresh";
  245. LLSideTray::getInstance()->showPanel("panel_group_info_sidetray", params);
  246. }
  247. //static 
  248. void LLGroupActions::createGroup()
  249. {
  250. LLSD params;
  251. params["group_id"] = LLUUID::null;
  252. params["open_tab_name"] = "panel_group_info_sidetray";
  253. params["action"] = "create";
  254. LLSideTray::getInstance()->showPanel("panel_group_info_sidetray", params);
  255. }
  256. //static
  257. void LLGroupActions::closeGroup(const LLUUID& group_id)
  258. {
  259. if(!isGroupUIVisible())
  260. return;
  261. LLSD params;
  262. params["group_id"] = group_id;
  263. params["open_tab_name"] = "panel_group_info_sidetray";
  264. params["action"] = "close";
  265. LLSideTray::getInstance()->showPanel("panel_group_info_sidetray", params);
  266. }
  267. // static
  268. void LLGroupActions::startIM(const LLUUID& group_id)
  269. {
  270. if (group_id.isNull())
  271. return;
  272. LLGroupData group_data;
  273. if (gAgent.getGroupData(group_id, group_data))
  274. {
  275. LLUUID session_id = gIMMgr->addSession(
  276. group_data.mName,
  277. IM_SESSION_GROUP_START,
  278. group_id);
  279. if (session_id != LLUUID::null)
  280. {
  281. LLIMFloater::show(session_id);
  282. }
  283. make_ui_sound("UISndStartIM");
  284. }
  285. else
  286. {
  287. // this should never happen, as starting a group IM session
  288. // relies on you belonging to the group and hence having the group data
  289. make_ui_sound("UISndInvalidOp");
  290. }
  291. }
  292. // static
  293. void LLGroupActions::endIM(const LLUUID& group_id)
  294. {
  295. if (group_id.isNull())
  296. return;
  297. LLUUID session_id = gIMMgr->computeSessionID(IM_SESSION_GROUP_START, group_id);
  298. if (session_id != LLUUID::null)
  299. {
  300. gIMMgr->leaveSession(session_id);
  301. }
  302. }
  303. // static
  304. bool LLGroupActions::isInGroup(const LLUUID& group_id)
  305. {
  306. // *TODO: Move all the LLAgent group stuff into another class, such as
  307. // this one.
  308. return gAgent.isInGroup(group_id);
  309. }
  310. // static
  311. bool LLGroupActions::isAvatarMemberOfGroup(const LLUUID& group_id, const LLUUID& avatar_id)
  312. {
  313. if(group_id.isNull() || avatar_id.isNull())
  314. {
  315. return false;
  316. }
  317. LLGroupMgrGroupData* group_data = LLGroupMgr::getInstance()->getGroupData(group_id);
  318. if(!group_data)
  319. {
  320. return false;
  321. }
  322. if(group_data->mMembers.end() == group_data->mMembers.find(avatar_id))
  323. {
  324. return false;
  325. }
  326. return true;
  327. }
  328. //-- Private methods ----------------------------------------------------------
  329. // static
  330. bool LLGroupActions::onLeaveGroup(const LLSD& notification, const LLSD& response)
  331. {
  332. S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
  333. LLUUID group_id = notification["payload"]["group_id"].asUUID();
  334. if(option == 0)
  335. {
  336. LLMessageSystem* msg = gMessageSystem;
  337. msg->newMessageFast(_PREHASH_LeaveGroupRequest);
  338. msg->nextBlockFast(_PREHASH_AgentData);
  339. msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  340. msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  341. msg->nextBlockFast(_PREHASH_GroupData);
  342. msg->addUUIDFast(_PREHASH_GroupID, group_id);
  343. gAgent.sendReliableMessage();
  344. }
  345. return false;
  346. }