
Untitled
By: a guest on
Jun 17th, 2012 | syntax:
None | size: 2.01 KB | hits: 18 | expires: Never
/*
C# Way
public UUID FindUUIDForName(string nameString)
{
ManualResetEvent NameSearchEvent = new ManualResetEvent(false);
UUID queryID = UUID.Random();
UUID found = UUID.Zero;
EventHandler<AvatarPickerReplyEventArgs> callback =
new EventHandler<AvatarPickerReplyEventArgs>((s, e) =>
{
if (queryID == e.QueryID)
{
foreach (KeyValuePair<UUID, string> kvp in e.Avatars)
{
if (kvp.Value == nameString) {
found = kvp.Key;
break;
}
}
NameSearchEvent.Set();
}
});
try
{
client.Avatars.AvatarPickerReply += callback;
// Send the Query
client.Avatars.RequestAvatarNameSearch(nameString, queryID);
NameSearchEvent.WaitOne(10000, false);
}
finally
{
client.Avatars.AvatarPickerReply -= callback;
}
}
*/
%% Prolog Way
findUUIDForName(NameString,Found):-
cli_call('UUID','Random',QID), % make a random UUID
botget(['Avatars'],AvMan), % get the AvatarManager object
cli_new_event_waiter(AvMan,'AvatarPickerReply',WaitOn), % create a new event handler object (and register it)
cli_call(AvMan,'RequestAvatarNameSearch'(NameString,QID),_), % make the request to the server
cli_block_until_event(WaitOn, 10000, c(Evt,cli_get(Evt,'QueryID',QID)), _), % wait for up to 10 seconds for the right the QueryID
cli_get(Evt,'Avatars',U2SDict), % get the UUID2Name dictionary
cli_map(U2SDict,Found,NameString), % Search that dictionary for the UUID by matching the String
cli_call(WaitOn,'Dispose',_). % unregister the handler and dispose