Files
libremetaverse/Programs/examples/TestClient/Commands/Communication/IMGroupCommand.cs
Jim Radford 1a886fb085 LIBOMV-375 Removes duplicate GroupPowers struct, adds XML comments to the one that stayed
LIBOMV-374 Adds new ModerateChatSessions method to AgentManager which allows a group member with Moderator rights to silence idiots
LIBOMV-372 Fixes exception thrown while using Group Chat functions caused by recent changes to the LL Simulator, Also fixes TestClient IMGroup command
* Adds (2) Events OnGroupChatJoin/OnGroupChatLeft fired when a member enters or leaves a group chat session



git-svn-id: http://libopenmetaverse.googlecode.com/svn/trunk@2207 52acb1d6-8a22-11de-b505-999d5b087335
2008-09-09 04:58:58 +00:00

79 lines
2.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Threading;
using OpenMetaverse;
using OpenMetaverse.Packets;
namespace OpenMetaverse.TestClient
{
public class ImGroupCommand : Command
{
UUID ToGroupID = UUID.Zero;
ManualResetEvent WaitForSessionStart = new ManualResetEvent(false);
public ImGroupCommand(TestClient testClient)
{
Name = "imgroup";
Description = "Send an instant message to a group. Usage: imgroup [group_uuid] [message]";
Category = CommandCategory.Communication;
}
public override string Execute(string[] args, UUID fromAgentID)
{
if (args.Length < 2)
return "Usage: imgroup [group_uuid] [message]";
if (UUID.TryParse(args[0], out ToGroupID))
{
string message = String.Empty;
for (int ct = 1; ct < args.Length; ct++)
message += args[ct] + " ";
message = message.TrimEnd();
if (message.Length > 1023) message = message.Remove(1023);
Client.Self.OnGroupChatJoin += new AgentManager.GroupChatJoinedCallback(Self_OnGroupChatJoin);
if (!Client.Self.GroupChatSessions.ContainsKey(ToGroupID))
{
WaitForSessionStart.Reset();
Client.Self.RequestJoinGroupChat(ToGroupID);
}
else
{
WaitForSessionStart.Set();
}
if (WaitForSessionStart.WaitOne(20000, false))
{
Client.Self.InstantMessageGroup(ToGroupID, message);
}
else
{
return "Timeout waiting for group session start";
}
Client.Self.OnGroupChatJoin -= new AgentManager.GroupChatJoinedCallback(Self_OnGroupChatJoin);
return "Instant Messaged group " + ToGroupID.ToString() + " with message: " + message;
}
else
{
return "failed to instant message group";
}
}
void Self_OnGroupChatJoin(UUID groupChatSessionID, string sessionName, UUID tmpSessionID, bool success)
{
if (success)
{
Console.WriteLine("Joined {0} Group Chat Success!", sessionName);
WaitForSessionStart.Set();
}
else
{
Console.WriteLine("Join Group Chat failed :(");
}
}
}
}