本文整理汇总了C#中OpenMetaverse.Http.CapsClient类的典型用法代码示例。如果您正苦于以下问题:C# CapsClient类的具体用法?C# CapsClient怎么用?C# CapsClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CapsClient类属于OpenMetaverse.Http命名空间,在下文中一共展示了CapsClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GatherErrorMessagesResponse
private void GatherErrorMessagesResponse(CapsClient client, OSD response, Exception error)
{
if (response is OSDMap)
{
_initializing++;
}
}
示例2: BeginLogin
private void BeginLogin()
{
LoginParams loginParams = CurrentContext.Value;
// Generate a random ID to identify this login attempt
loginParams.LoginID = UUID.Random();
CurrentContext = loginParams;
#region Sanity Check loginParams
if (loginParams.Options == null)
loginParams.Options = new List<string>().ToArray();
// Convert the password to MD5 if it isn't already
if (loginParams.Password.Length != 35 && !loginParams.Password.StartsWith("$1$"))
loginParams.Password = Utils.MD5(loginParams.Password);
if (loginParams.ViewerDigest == null)
loginParams.ViewerDigest = String.Empty;
if (loginParams.Version == null)
loginParams.Version = String.Empty;
if (loginParams.UserAgent == null)
loginParams.UserAgent = String.Empty;
if (loginParams.Platform == null)
loginParams.Platform = String.Empty;
if (loginParams.MAC == null)
loginParams.MAC = String.Empty;
if (loginParams.Channel == null)
loginParams.Channel = String.Empty;
if (loginParams.Author == null)
loginParams.Author = String.Empty;
#endregion
// TODO: Allow a user callback to be defined for handling the cert
ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
// Even though this will compile on Mono 2.4, it throws a runtime exception
//ServicePointManager.ServerCertificateValidationCallback = TrustAllCertificatePolicy.TrustAllCertificateHandler;
if (Client.Settings.USE_LLSD_LOGIN)
{
#region LLSD Based Login
// Create the CAPS login structure
OSDMap loginLLSD = new OSDMap();
loginLLSD["first"] = OSD.FromString(loginParams.FirstName);
loginLLSD["last"] = OSD.FromString(loginParams.LastName);
loginLLSD["passwd"] = OSD.FromString(loginParams.Password);
loginLLSD["start"] = OSD.FromString(loginParams.Start);
loginLLSD["channel"] = OSD.FromString(loginParams.Channel);
loginLLSD["version"] = OSD.FromString(loginParams.Version);
loginLLSD["platform"] = OSD.FromString(loginParams.Platform);
loginLLSD["mac"] = OSD.FromString(loginParams.MAC);
loginLLSD["agree_to_tos"] = OSD.FromBoolean(loginParams.AgreeToTos);
loginLLSD["read_critical"] = OSD.FromBoolean(loginParams.ReadCritical);
loginLLSD["viewer_digest"] = OSD.FromString(loginParams.ViewerDigest);
loginLLSD["id0"] = OSD.FromString(loginParams.ID0);
// Create the options LLSD array
OSDArray optionsOSD = new OSDArray();
for (int i = 0; i < loginParams.Options.Length; i++)
optionsOSD.Add(OSD.FromString(loginParams.Options[i]));
foreach (string[] callbackOpts in CallbackOptions.Values)
{
if (callbackOpts != null)
{
for (int i = 0; i < callbackOpts.Length; i++)
{
if (!optionsOSD.Contains(callbackOpts[i]))
optionsOSD.Add(callbackOpts[i]);
}
}
}
loginLLSD["options"] = optionsOSD;
// Make the CAPS POST for login
Uri loginUri;
try
{
loginUri = new Uri(loginParams.URI);
}
catch (Exception ex)
{
Logger.Log(String.Format("Failed to parse login URI {0}, {1}", loginParams.URI, ex.Message),
Helpers.LogLevel.Error, Client);
return;
}
CapsClient loginRequest = new CapsClient(loginUri);
loginRequest.OnComplete += new CapsClient.CompleteCallback(LoginReplyLLSDHandler);
loginRequest.UserData = CurrentContext;
UpdateLoginStatus(LoginStatus.ConnectingToLogin, String.Format("Logging in as {0} {1}...", loginParams.FirstName, loginParams.LastName));
loginRequest.BeginGetResponse(loginLLSD, OSDFormat.Xml, Client.Settings.CAPS_TIMEOUT);
//.........这里部分代码省略.........
示例3: ProvisionCapsResponse
private void ProvisionCapsResponse(CapsClient client, OSD response, Exception error)
{
if (response is OSDMap)
{
OSDMap respTable = (OSDMap)response;
if (OnProvisionAccount != null)
{
try { OnProvisionAccount(respTable["username"].AsString(), respTable["password"].AsString()); }
catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); }
}
}
}
示例4: StartIMConference
/// <summary>
/// Start a friends conference
/// </summary>
/// <param name="participants"><seealso cref="UUID"/> List of UUIDs to start a conference with</param>
/// <param name="tmp_session_id">the temportary session ID returned in the <see cref="OnJoinedGroupChat"/> callback></param>
public void StartIMConference(List<UUID> participants, UUID tmp_session_id)
{
if (Client.Network.CurrentSim == null || Client.Network.CurrentSim.Caps == null)
throw new Exception("ChatSessionRequest capability is not currently available");
Uri url = Client.Network.CurrentSim.Caps.CapabilityURI("ChatSessionRequest");
if (url != null)
{
ChatSessionRequestStartConference startConference = new ChatSessionRequestStartConference();
startConference.AgentsBlock = new UUID[participants.Count];
for (int i = 0; i < participants.Count; i++)
startConference.AgentsBlock[i] = participants[i];
startConference.SessionID = tmp_session_id;
CapsClient request = new CapsClient(url);
request.BeginGetResponse(startConference.Serialize(), OSDFormat.Xml, Client.Settings.CAPS_TIMEOUT);
}
else
{
throw new Exception("ChatSessionRequest capability is not currently available");
}
}
示例5: ModerateChatSessions
/// <summary>
/// Moderate a chat session
/// </summary>
/// <param name="sessionID">the <see cref="UUID"/> of the session to moderate, for group chats this will be the groups UUID</param>
/// <param name="memberID">the <see cref="UUID"/> of the avatar to moderate</param>
/// <param name="key">Either "voice" to moderate users voice, or "text" to moderate users text session</param>
/// <param name="moderate">true to moderate (silence user), false to allow avatar to speak</param>
public void ModerateChatSessions(UUID sessionID, UUID memberID, string key, bool moderate)
{
if (Client.Network.CurrentSim == null || Client.Network.CurrentSim.Caps == null)
throw new Exception("ChatSessionRequest capability is not currently available");
Uri url = Client.Network.CurrentSim.Caps.CapabilityURI("ChatSessionRequest");
if (url != null)
{
ChatSessionRequestMuteUpdate req = new ChatSessionRequestMuteUpdate();
req.RequestKey = key;
req.RequestValue = moderate;
req.SessionID = sessionID;
req.AgentID = memberID;
CapsClient request = new CapsClient(url);
request.BeginGetResponse(req.Serialize(), OSDFormat.Xml, Client.Settings.CAPS_TIMEOUT);
}
else
{
throw new Exception("ChatSessionRequest capability is not currently available");
}
}
示例6: UploadInventoryAssetResponse
private void UploadInventoryAssetResponse(CapsClient client, OSD result, Exception error)
{
OSDMap contents = result as OSDMap;
KeyValuePair<InventoryUploadedAssetCallback, byte[]> kvp = (KeyValuePair<InventoryUploadedAssetCallback, byte[]>)(((object[])client.UserData)[0]);
InventoryUploadedAssetCallback callback = kvp.Key;
byte[] itemData = (byte[])kvp.Value;
if (error == null && contents != null)
{
string status = contents["state"].AsString();
if (status == "upload")
{
Uri uploadURL = contents["uploader"].AsUri();
if (uploadURL != null)
{
// This makes the assumption that all uploads go to CurrentSim, to avoid
// the problem of HttpRequestState not knowing anything about simulators
CapsClient upload = new CapsClient(uploadURL);
upload.OnComplete += UploadInventoryAssetResponse;
upload.UserData = new object[2] { kvp, (UUID)(((object[])client.UserData)[1]) };
upload.BeginGetResponse(itemData, "application/octet-stream", Client.Settings.CAPS_TIMEOUT);
}
else
{
try { callback(false, "Missing uploader URL", UUID.Zero, UUID.Zero); }
catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); }
}
}
else if (status == "complete")
{
if (contents.ContainsKey("new_asset"))
{
// Request full item update so we keep store in sync
RequestFetchInventory((UUID)(((object[])client.UserData)[1]), contents["new_asset"].AsUUID());
try { callback(true, String.Empty, (UUID)(((object[])client.UserData)[1]), contents["new_asset"].AsUUID()); }
catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); }
}
else
{
try { callback(false, "Failed to parse asset and item UUIDs", UUID.Zero, UUID.Zero); }
catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); }
}
}
else
{
try { callback(false, status, UUID.Zero, UUID.Zero); }
catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); }
}
}
else
{
string message = "Unrecognized or empty response";
if (error != null)
{
if (error is WebException)
message = ((HttpWebResponse)((WebException)error).Response).StatusDescription;
if (message == null || message == "None")
message = error.Message;
}
try { callback(false, message, UUID.Zero, UUID.Zero); }
catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); }
}
}
示例7: RequestUploadBakedTexture
public void RequestUploadBakedTexture(byte[] textureData, BakedTextureUploadedCallback callback)
{
Uri url = null;
Caps caps = Client.Network.CurrentSim.Caps;
if (caps != null)
url = caps.CapabilityURI("UploadBakedTexture");
if (url != null)
{
// Fetch the uploader capability
CapsClient request = new CapsClient(url);
request.OnComplete +=
delegate(CapsClient client, OSD result, Exception error)
{
if (error == null && result is OSDMap)
{
UploadBakedTextureMessage message = new UploadBakedTextureMessage();
message.Deserialize((OSDMap)result);
if (message.Request.State == "upload")
{
Uri uploadUrl = ((UploaderRequestUpload)message.Request).Url;
if (uploadUrl != null)
{
// POST the asset data
CapsClient upload = new CapsClient(uploadUrl);
upload.OnComplete +=
delegate(CapsClient client2, OSD result2, Exception error2)
{
if (error2 == null && result2 is OSDMap)
{
UploadBakedTextureMessage message2 = new UploadBakedTextureMessage();
message2.Deserialize((OSDMap)result2);
if (message2.Request.State == "complete")
{
callback(((UploaderRequestComplete)message2.Request).AssetID);
return;
}
}
Logger.Log("Bake upload failed during asset upload", Helpers.LogLevel.Warning, Client);
callback(UUID.Zero);
};
upload.BeginGetResponse(textureData, "application/octet-stream", Client.Settings.CAPS_TIMEOUT);
return;
}
}
}
Logger.Log("Bake upload failed during uploader retrieval", Helpers.LogLevel.Warning, Client);
callback(UUID.Zero);
};
request.BeginGetResponse(new OSDMap(), OSDFormat.Xml, Client.Settings.CAPS_TIMEOUT);
}
else
{
Logger.Log("UploadBakedTexture not available, falling back to UDP method", Helpers.LogLevel.Info, Client);
ThreadPool.QueueUserWorkItem(
delegate(object o)
{
UUID transactionID = UUID.Random();
BakedTextureUploadedCallback uploadCallback = (BakedTextureUploadedCallback)o;
AutoResetEvent uploadEvent = new AutoResetEvent(false);
EventHandler<AssetUploadEventArgs> udpCallback =
delegate(object sender, AssetUploadEventArgs e)
{
if (e.Upload.ID == transactionID)
{
uploadEvent.Set();
uploadCallback(e.Upload.Success ? e.Upload.AssetID : UUID.Zero);
}
};
AssetUploaded += udpCallback;
UUID assetID;
bool success;
try
{
RequestUpload(out assetID, AssetType.Texture, textureData, true, transactionID);
success = uploadEvent.WaitOne(Client.Settings.TRANSFER_TIMEOUT, false);
}
catch (Exception)
{
success = false;
}
AssetUploaded -= udpCallback;
if (!success)
uploadCallback(UUID.Zero);
}, callback
);
}
}
示例8: MapLayerResponseHandler
protected void MapLayerResponseHandler(CapsClient client, OSD result, Exception error)
{
if (result == null)
{
Logger.Log("MapLayerResponseHandler error: " + error.Message + ": " + error.StackTrace, Helpers.LogLevel.Error, Client);
return;
}
OSDMap body = (OSDMap)result;
OSDArray layerData = (OSDArray)body["LayerData"];
if (m_GridLayer != null)
{
for (int i = 0; i < layerData.Count; i++)
{
OSDMap thisLayerData = (OSDMap)layerData[i];
GridLayer layer;
layer.Bottom = thisLayerData["Bottom"].AsInteger();
layer.Left = thisLayerData["Left"].AsInteger();
layer.Top = thisLayerData["Top"].AsInteger();
layer.Right = thisLayerData["Right"].AsInteger();
layer.ImageID = thisLayerData["ImageID"].AsUUID();
OnGridLayer(new GridLayerEventArgs(layer));
}
}
if (body.ContainsKey("MapBlocks"))
{
// TODO: At one point this will become activated
Logger.Log("Got MapBlocks through CAPS, please finish this function!", Helpers.LogLevel.Error, Client);
}
}
示例9: NavigateObjectMedia
/// <summary>
/// Update current URL of the previously set prim media
/// </summary>
/// <param name="primID">UUID of the prim</param>
/// <param name="newURL">Set current URL to this</param>
/// <param name="face">Prim face number</param>
/// <param name="sim">Simulator in which prim is located</param>
public void NavigateObjectMedia(UUID primID, int face, string newURL, Simulator sim)
{
Uri url;
if (sim.Caps != null && null != (url = sim.Caps.CapabilityURI("ObjectMediaNavigate")))
{
ObjectMediaNavigateMessage req = new ObjectMediaNavigateMessage();
req.PrimID = primID;
req.URL = newURL;
req.Face = face;
CapsClient request = new CapsClient(url);
request.OnComplete += (CapsClient client, OSD result, Exception error) =>
{
if (error != null)
{
Logger.Log("ObjectMediaNavigate: " + error.Message, Helpers.LogLevel.Error, Client);
}
};
request.BeginGetResponse(req.Serialize(), OSDFormat.Xml, Client.Settings.CAPS_TIMEOUT);
}
else
{
Logger.Log("ObjectMediaNavigate capability not available", Helpers.LogLevel.Error, Client);
}
}
示例10: UpdateAgentLanguage
/// <summary>
/// Tells the sim what UI language is used, and if it's ok to share that with scripts
/// </summary>
/// <param name="language">Two letter language code</param>
/// <param name="isPublic">Share language info with scripts</param>
public void UpdateAgentLanguage(string language, bool isPublic)
{
try
{
UpdateAgentLanguageMessage msg = new UpdateAgentLanguageMessage();
msg.Language = language;
msg.LanguagePublic = isPublic;
Uri url = Client.Network.CurrentSim.Caps.CapabilityURI("UpdateAgentLanguage");
if (url != null)
{
CapsClient request = new CapsClient(url);
request.BeginGetResponse(msg.Serialize(), OSDFormat.Xml, Client.Settings.CAPS_TIMEOUT);
}
}
catch (Exception ex)
{
Logger.Log("Failes to update agent language", Helpers.LogLevel.Error, Client, ex);
}
}
示例11: RequestMapLayer
/// <summary>
///
/// </summary>
/// <param name="layer"></param>
public void RequestMapLayer(GridLayerType layer)
{
Uri url = Client.Network.CurrentSim.Caps.CapabilityURI("MapLayer");
if (url != null)
{
OSDMap body = new OSDMap();
body["Flags"] = OSD.FromInteger((int)layer);
CapsClient request = new CapsClient(url);
request.OnComplete += new CapsClient.CompleteCallback(MapLayerResponseHandler);
request.BeginGetResponse(body, OSDFormat.Xml, Client.Settings.CAPS_TIMEOUT);
}
}
示例12: SetDisplayName
/// <summary>
/// Initates request to set a new display name
/// </summary>
/// <param name="oldName">Previous display name</param>
/// <param name="newName">Desired new display name</param>
public void SetDisplayName(string oldName, string newName)
{
Uri uri;
if (Client.Network.CurrentSim == null ||
Client.Network.CurrentSim.Caps == null ||
(uri = Client.Network.CurrentSim.Caps.CapabilityURI("SetDisplayName")) == null)
{
Logger.Log("Unable to invoke SetDisplyName capability at this time", Helpers.LogLevel.Warning, Client);
return;
}
SetDisplayNameMessage msg = new SetDisplayNameMessage();
msg.OldDisplayName = oldName;
msg.NewDisplayName = newName;
CapsClient cap = new CapsClient(uri);
cap.BeginGetResponse(msg.Serialize(), OSDFormat.Xml, Client.Settings.CAPS_TIMEOUT);
}
示例13: SetAgentAccess
/// <summary>
/// Sets agents maturity access level
/// </summary>
/// <param name="access">PG, M or A</param>
/// <param name="callback">Callback function</param>
public void SetAgentAccess(string access, AgentAccessCallback callback)
{
if (Client == null || !Client.Network.Connected || Client.Network.CurrentSim.Caps == null) return;
Uri url = Client.Network.CurrentSim.Caps.CapabilityURI("UpdateAgentInformation");
if (url == null) return;
CapsClient request = new CapsClient(url);
request.OnComplete += (client, result, error) =>
{
bool success = true;
if (error == null && result is OSDMap)
{
var map = ((OSDMap)result)["access_prefs"];
agentAccess = ((OSDMap)map)["max"];
Logger.Log("Max maturity access set to " + agentAccess, Helpers.LogLevel.Info, Client );
}
else if (error == null)
{
Logger.Log("Max maturity unchanged at " + agentAccess, Helpers.LogLevel.Info, Client);
}
else
{
Logger.Log("Failed setting max maturity access.", Helpers.LogLevel.Warning, Client);
success = false;
}
if (callback != null)
{
try { callback(new AgentAccessEventArgs(success, agentAccess)); }
catch { }
}
};
OSDMap req = new OSDMap();
OSDMap prefs = new OSDMap();
prefs["max"] = access;
req["access_prefs"] = prefs;
request.BeginGetResponse(req, OSDFormat.Xml, Client.Settings.CAPS_TIMEOUT);
}
示例14: GatherLastNamesResponse
private void GatherLastNamesResponse(CapsClient client, OSD response, Exception error)
{
if (response is OSDMap)
{
}
}
示例15: RequestUpdateScriptTask
/// <summary>
/// Update an existing script in an task Inventory
/// </summary>
/// <param name="data">A byte[] array containing the encoded scripts contents</param>
/// <param name="itemID">the itemID of the script</param>
/// <param name="taskID">UUID of the prim containting the script</param>
/// <param name="mono">if true, sets the script content to run on the mono interpreter</param>
/// <param name="running">if true, sets the script to running</param>
/// <param name="callback"></param>
public void RequestUpdateScriptTask(byte[] data, UUID itemID, UUID taskID, bool mono, bool running, ScriptUpdatedCallback callback)
{
Uri url = Client.Network.CurrentSim.Caps.CapabilityURI("UpdateScriptTask");
if (url != null)
{
UpdateScriptTaskUpdateMessage msg = new UpdateScriptTaskUpdateMessage();
msg.ItemID = itemID;
msg.TaskID = taskID;
msg.ScriptRunning = running;
msg.Target = mono ? "mono" : "lsl2";
CapsClient request = new CapsClient(url);
request.OnComplete += new CapsClient.CompleteCallback(UpdateScriptAgentInventoryResponse);
request.UserData = new object[2] { new KeyValuePair<ScriptUpdatedCallback, byte[]>(callback, data), itemID };
request.BeginGetResponse(msg.Serialize(), OSDFormat.Xml, Client.Settings.CAPS_TIMEOUT);
}
else
{
throw new Exception("UpdateScriptTask capability is not currently available");
}
}