public override CmdResult ExecuteRequest(CmdRequest args) { // Get the agent's current "patch" position, where each patch of // wind data is a 16x16m square int argsUsed; SimPosition aPos = WorldSystem.GetVector(args, out argsUsed); Vector3 agentPos = aPos.SimPosition; int xPos = (int)Utils.Clamp(agentPos.X, 0.0f, 255.0f) / 16; int yPos = (int)Utils.Clamp(agentPos.Y, 0.0f, 255.0f) / 16; Simulator sim = SimRegion.GetRegion(aPos.GlobalPosition).TheSimulator; if (sim == null) { return(Failure("Unknown simulator for " + aPos)); } ulong handle = sim.Handle; if (sim.WindSpeeds == null) { return(Failure("Unknown wind speed at sim: " + sim)); } Vector2[] windSpeeds = sim.WindSpeeds; Vector2 windSpeed = windSpeeds[yPos * 16 + xPos]; return(Success("Wind speed at " + aPos + " is " + windSpeed)); }
public override void Parcels_OnParcelProperties(object sender, ParcelPropertiesEventArgs e) { Simulator simulator = e.Simulator; var parcel = e.Parcel; SimRegion r = SimRegion.GetRegion(simulator); r.Parcels_OnParcelProperties(simulator, parcel, e.Result, e.SelectedPrims, e.SequenceID, e.SnapSelection); //base.Parcels_OnParcelProperties(simulator, parcel, result, selectedPrims, sequenceID, snapSelection); }
private void FindNewMaster(ulong handle) { IEnumerable <Simulator> _AllSimulators = AllSimulators; SimRegion R = SimRegion.GetRegion(handle); lock (_AllSimulators) { foreach (var simulator in _AllSimulators) { if (simulator.Client == client.gridClient) { continue; } if (simulator.Handle != handle) { continue; } GridClient cl = simulator.Client; R.SetMaster(cl); BotClient bc = BotClientFor(cl); if (SimRegion.IsMaster(simulator, bc.gridClient)) { bc.WorldSystem.MasteringRegions.Add(handle); } else { bc.WorldSystem.MasteringRegions.Add(handle); } Debug("Found a strong new client for region " + R + " as " + cl); return; } foreach (var simulator in _AllSimulators) { // if (simulator.Client == client.gridClient) continue; if (simulator.Handle != handle) { continue; } GridClient cl = simulator.Client; BotClient bc = BotClientFor(cl); if (SimRegion.IsMaster(simulator, bc.gridClient)) { bc.WorldSystem.MasteringRegions.Add(handle); } if (!cl.Network.Simulators.Contains(simulator)) { continue; } R.SetMaster(cl); Debug("Found a new client for region " + R + " as " + cl); return; } } Debug("UHT OH, No client is Mastering for region " + R); }
public override void Parcels_OnParcelSelectedObjects(object sender, ForceSelectObjectsReplyEventArgs e) { Simulator simulator = e.Simulator; var objectIDs = e.ObjectIDs; var resetList = e.ResetList; SimRegion r = SimRegion.GetRegion(simulator); r.Parcels_OnParcelSelectedObjects(simulator, objectIDs, resetList); base.Parcels_OnParcelSelectedObjects(sender, e); }
internal SimRegion GetRegion(ulong RegionHandle) { if (RegionHandle == 0) { return(null); } var R = SimRegion.GetRegion(RegionHandle, client); R.RegionMaster = client; R.TheWorldSystem = this; return(R); }
public override void Parcels_OnAccessListReply(object sender, ParcelAccessListReplyEventArgs e) { return; SimRegion r = SimRegion.GetRegion(e.Simulator.RegionID, client); if (r != null) { r.Parcels_OnAccessList(e); } //base.Parcels_OnAccessListReply(simulator, sequenceID, localID, flags, accessEntries); }
public override void Parcels_OnParcelInfo(object sender, ParcelInfoReplyEventArgs e) { var parcel = e.Parcel; SimRegion r = SimRegion.GetRegion(parcel.SimName, client); if (r != null) { r.Parcels_OnParcelInfo(parcel); } else { base.Parcels_OnParcelInfo(sender, e); } }
public override void Grid_OnGridRegion(object sender, GridRegionEventArgs e) { var region = e.Region; SimRegion R = SimRegion.GetRegion(region.RegionHandle, client); if (R != null) { R.GridInfo = region; R.TheWorldSystem = this; R.RegionMaster = client; } // base.Grid_OnGridRegion(region); }
private object AsRLocation(Simulator simulator, Vector3d targetPos, SimPosition pos) { Vector3 lpos = new Vector3((float)targetPos.X, (float)targetPos.Y, (float)targetPos.Z); SimRegion r = SimRegion.GetRegion(simulator); if (targetPos == Vector3d.Zero) { if (r == null) { if (pos != null && pos.IsRegionAttached) { return(new SimHeading(pos)); } return(SimHeading.UNKNOWN); } return(r); } return(new SimHeading(pos, lpos)); }
public override void Network_OnSimDisconnected(object sender, SimDisconnectedEventArgs e) { var simulator = e.Simulator; var reason = e.Reason; base.Network_OnSimDisconnected(sender, e); RemoveSim(simulator); SimRegion.GetRegion(simulator).RemoveSim(simulator); LeaveSimulator(simulator); if (simulator == client.Network.CurrentSim) { PropertyQueue.AddFirst(() => { Debug("CLOSE for region " + simulator); //client.Login(); } ); } }
public override void Network_OnDisconnected(object sender, DisconnectedEventArgs e) { { foreach (var simulator in AllSimulators) { if (simulator.Client != client.gridClient) { if (GridMaster == this && simulator.Connected) { GridMaster = BotClientFor(simulator.Client).WorldSystem; Debug("Changed GridMaster to " + GridMaster); } continue; } RemoveSim(simulator); SimRegion.GetRegion(simulator).RemoveSim(simulator); LeaveSimulator(simulator); } } base.Network_OnDisconnected(sender, e); }
public override CmdResult ExecuteRequest(CmdRequest args) { if (args.Length == 0) { //foreach (SimRegion R in SimRegion.CurrentRegions) //{ // R.ShowDebugger(); //} SimRegion.GetRegion(Client.Network.CurrentSim).ShowDebugger(); } else { foreach (SimRegion R in SimRegion.CurrentRegions) { if (R.RegionName.Contains(String.Join(" ", args))) { R.ShowDebugger(); } } } return(Success("Ran " + Name)); }
public void EnsureSimulator(Simulator simulator) { if (simulator == null || simulator.Handle == 0) { return; } if (!Monitor.TryEnter(_AllSimulators, 10000)) { WriteLine("Cant lock _AllSimulators"); return; } lock (SimMaster) { if (!SimMaster.ContainsKey(simulator.Handle)) { SimMaster[simulator.Handle] = this; MasteringRegions.AddTo(simulator.Handle); } } try { { foreach (Simulator set in _AllSimulators) { if (set.Handle == simulator.Handle && set.Client == simulator.Client) { return; } } _AllSimulators.Add(simulator); } SimRegion.GetRegion(simulator); } finally { Monitor.Exit(_AllSimulators); } }
public string RezAll(BotInventoryEval man, InventoryBase b, SimPosition dest) { string ret = ""; var manager = man.Manager; if (b is InventoryItem) { InventoryItem item = b as InventoryItem; bool canCopy = (item.Permissions.OwnerMask & PermissionMask.Copy) == PermissionMask.Copy; ret += item.Name + nl; if (dest == null) { Simulator sim = Client.Network.CurrentSim; Client.Inventory.RequestRestoreRezFromInventory(sim, item, item.UUID); } else { Simulator sim = SimRegion.GetRegion(dest.GlobalPosition).TheSimulator; Client.Inventory.RequestRezFromInventory(sim, dest.SimRotation, dest.SimPosition, item, UUID.Zero); } } else if (b is InventoryFolder) { InventoryFolder folder = b as InventoryFolder; List <InventoryBase> folderContents = man.FolderContents(folder.UUID); if (folderContents != null) { foreach (InventoryBase list in folderContents) { ret += RezAll(man, list, dest); } } } return(ret); }
public Simulator TryGetSim(string[] args, out int argsUsed) { if (args.Length > 0) { string s = String.Join(" ", args); SimRegion R = SimRegion.GetRegion(s, client); if (R == null) { argsUsed = 0; WriteLine("cant find sim " + s); return(null); } Simulator sim = R.TheSimulator; if (sim == null) { WriteLine("not connect to sim" + R); } argsUsed = args.Length; return(sim); } argsUsed = 0; return(client.Network.CurrentSim); }
private object AsLocation(Simulator simulator, Vector3 position, SimPosition pos) { SimRegion r = SimRegion.GetRegion(simulator); if (position == Vector3.Zero) { if (r == null) { if (pos != null && pos.IsRegionAttached) { return(new SimHeading(pos)); } return(SimHeading.UNKNOWN); } return(r); } Quaternion rot = Quaternion.Identity; if (pos != null && pos.IsRegionAttached) { rot = pos.SimRotation; } return(new SimHeading(r.GetPathStore(position), position, rot)); }
private void SaveParcelInfo(ImportSettings settings) { var CurSim = settings.CurSim; Client.Parcels.RequestAllSimParcels(CurSim); if (CurSim.IsParcelMapFull()) { ParcelsDownloaded.Set(); } if (ParcelsDownloaded.WaitOne(30000, false) && Client.Network.Connected) { Success(string.Format("Downloaded {0} Parcels in {1} " + Environment.NewLine, CurSim.Parcels.Count, CurSim.Name)); IDictionary <int, Parcel> curSimParcels = null; lock (CurSim.Parcels.Dictionary) { curSimParcels = LockInfo.CopyOf(CurSim.Parcels.Dictionary); } List <UUID> ParcelPrimOwners = new List <UUID>(); List <uint> ParcelObjectIDS = new List <uint>(); foreach (KeyValuePair <int, Parcel> simParcel in curSimParcels) { var parcel = simParcel.Value; int parcelID = parcel.LocalID; Success(string.Format( "Parcel[{0}]: Name: \"{1}\", Description: \"{2}\" ACLBlacklist Count: {3}, ACLWhiteList Count: {5} Traffic: {4}" + Environment.NewLine, parcel.LocalID, parcel.Name, parcel.Desc, parcel.AccessBlackList.Count, parcel.Dwell, parcel.AccessWhiteList.Count)); AddExportUser(parcel.OwnerID); AddExportGroup(parcel.GroupID); Success(Helpers.StructToString(parcel)); foreach ( ParcelManager.ParcelAccessEntry white in parcel.AccessWhiteList) { if (white.AgentID != UUID.Zero) { Success(string.Format( "\tAllowed Avatar {0}" + Environment.NewLine, white.AgentID)); } } foreach ( ParcelManager.ParcelAccessEntry black in parcel.AccessBlackList) { // if(black.AgentID != UUID.Zero) Success(string.Format("\t Banned Avatar {0}" + Environment.NewLine, black.AgentID)); } { AutoResetEvent parcelOwnerWait = new AutoResetEvent(false); EventHandler <ParcelObjectOwnersReplyEventArgs> callback = delegate(object sender, ParcelObjectOwnersReplyEventArgs e) { for (int i = 0; i < e.PrimOwners.Count; i++) { ParcelManager.ParcelPrimOwners ownerse = e.PrimOwners[i]; if (ownerse.IsGroupOwned) { AddExportGroup(ownerse.OwnerID); } else { AddExportUser(ownerse.OwnerID); } Success(string.Format("Owner: {0} Count: {1}" + Environment.NewLine, ownerse.OwnerID, ownerse.Count)); if (!CogbotHelpers.IsNullOrZero(ownerse.OwnerID)) { ParcelPrimOwners.Add(ownerse.OwnerID); } } parcelOwnerWait.Set(); }; Client.Parcels.ParcelObjectOwnersReply += callback; try { Client.Parcels.RequestObjectOwners(CurSim, parcelID); if (!parcelOwnerWait.WaitOne(10000, false)) { Failure("Timed out waiting for packet."); } } finally { Client.Parcels.ParcelObjectOwnersReply -= callback; } } foreach (UUID ownerUUID in ParcelPrimOwners) { AutoResetEvent wait = new AutoResetEvent(false); EventHandler <ForceSelectObjectsReplyEventArgs> callback = delegate(object sender, ForceSelectObjectsReplyEventArgs e) { ParcelObjectIDS.AddRange(e.ObjectIDs); for (int i = 0; i < e.ObjectIDs.Count; i++) { // Success(string.Format(e.ObjectIDs[i].ToString() + " ")); // counter++; } if (e.ObjectIDs.Count < 251) { wait.Set(); } }; Client.Parcels.ForceSelectObjectsReply += callback; Client.Parcels.RequestSelectObjects(parcelID, (ObjectReturnType)16, ownerUUID); wait.WaitOne(10000); } } foreach (uint u in ParcelObjectIDS) { RequiredForExportLocalIDs.Add(u); } Success("Parcel LocalIDs=" + ParcelObjectIDS.Count + " ParcelOwners=" + ParcelPrimOwners.Count); } else { Failure("Failed to retrieve information on all the simulator parcels"); } string parcelDirs = settings.OarDir + "landdata/"; Directory.CreateDirectory(parcelDirs); SimRegion r = SimRegion.GetRegion(CurSim); foreach (var p in r.ParcelMap) { Parcel parcel = p.Value; if (CogbotHelpers.IsNullOrZero(parcel.GlobalID)) { parcel.GlobalID = UUID.Random(); } File.WriteAllText(parcelDirs + "" + parcel.GlobalID + ".xml", OarFile.Serialize(parcel)); } }
public SimPosition GetVector(string[] args, out int argsUsed, SimPosition offset) { argsUsed = 0; if (args.Length == 0) { return(offset ?? TheSimAvatar); } //if (args.Length >= 2) { SimPosition R = GetSimV(args, 0, out argsUsed, offset); if (R != null) { return(R); } } UUID uuid = UUID.Zero; if (UUID.TryParse(args[0], out uuid)) { SimObject O = null; O = GetSimObjectFromUUID(uuid); if (O != null) { argsUsed = 1; return(O); } } List <SimObject> prim = GetSingleArg(args, out argsUsed); if (prim.Count == 1) { return(prim[0]); } argsUsed = 0; string destination = String.Empty; // Handle multi-word sim names by combining the arguments foreach (string arg in args) { destination += arg + " "; } int consume = args.Length; destination = destination.Trim(); string[] tokens = destination.Split(new char[] { '/' }); float x, y = 128; if (!float.TryParse(tokens[0], out x)) { x = 128; } else { argsUsed++; } string sim = tokens[argsUsed]; //TODO use the GetSimV code argsUsed += 1; float z = -1; if (tokens.Length > argsUsed + 1) { if (!float.TryParse(tokens[argsUsed], out x) || !float.TryParse(tokens[argsUsed + 1], out y)) { return(null); } argsUsed += 2; if (tokens.Length > argsUsed) { if (float.TryParse(tokens[argsUsed], out z)) { argsUsed += 1; } else { z = -1; } } // test for global if (x > 512 || y > 512) { float.TryParse(tokens[argsUsed], out z); return(SimWaypointImpl.CreateGlobal(x, y, z)); } } SimRegion region = SimRegion.GetRegion(sim, client); if (region == null) { return(null); } if (z == -1) { z = region.AverageHieght; } Vector3 v3 = new Vector3(x, y, z); return(SimWaypointImpl.CreateLocal(v3, region.GetPathStore(v3))); }
public SimRegion GetRegion(UUID uuid) { return(SimRegion.GetRegion(uuid, client)); }
private void Objects_OnPrimitiveUpdateReal(Simulator simulator, Primitive av, ObjectMovementUpdate update, ulong RegionHandle, ushort TimeDilation) { if (!IsMaster(simulator)) { return; } if (av == null) { return; } if (av.ID == UUID.Zero) { return; // too early } SimObject AV = null; Object Obj; //lock (uuidTypeObject) if (UUIDTypeObjectTryGetValue(av.ID, out Obj)) { AV = Obj as SimObject; } else { if (av.ID == client.Self.AgentID) { AV = GetSimObject(av, simulator); } } if (AV != null) { Primitive prev = AV.Prim; if (prev == null) { AV.SetFirstPrim(av); } if (av.ParentID == 0 && !SimRegion.OutOfRegion(av.Position)) { AV.ResetPrim(av, client, simulator); } if (prev != null) { // parent changed? if (prev.ParentID != av.ParentID) { AV.Parent = null; } } if (av.ParentID == 0 && !SimRegion.OutOfRegion(update.Position)) { if (update.Avatar) { SimRegion.GetRegion(simulator).UpdateTraveled(av.ID, av.Position, av.Rotation); //return; } } if (!MaintainObjectUpdates) { return; } EventQueue.Enqueue(() => Objects_OnObjectUpdated1(simulator, av, updatFromSimObject(AV), RegionHandle, TimeDilation)); } }
private void Self_OnMessage(string FromAgentName, UUID FromAgentID, UUID ToAgentID, string Message, UUID IMSessionID, bool GroupIM, UUID RegionID, Vector3 Position, InstantMessageDialog Dialog, ChatType Type, EventArgs origin) { if (Dialog == InstantMessageDialog.GroupNotice) { GroupIM = true; } BotPermissions perms = GetSecurityLevel(FromAgentID, FromAgentName); // Received an IM from someone that is authenticated if (Type == ChatType.OwnerSay) { perms |= BotPermissions.Owner; } bool displayedMessage = false; if (origin is ChatEventArgs && Message.Length > 0 && Dialog == InstantMessageDialog.MessageFromAgent) { WriteLine(String.Format("{0} says, \"{1}\".", FromAgentName, Message)); PosterBoard["/posterboard/onchat"] = Message; if (FromAgentName == Self.Name) { PosterBoard["/posterboard/onchat-said"] = Message; } else { PosterBoard["/posterboard/onchat-heard"] = Message; } } bool groupIM = GroupIM && GroupMembers != null && GroupMembers.ContainsKey(FromAgentID) ? true : false; switch (Dialog) { case InstantMessageDialog.MessageBox: break; case InstantMessageDialog.GroupInvitation: if ((perms & BotPermissions.AcceptGroupAndFriendRequests) != 0) { string groupName = Message; int found = groupName.IndexOf("Group:"); if (found > 0) { groupName = groupName.Substring(found + 6); } Self.InstantMessage(Self.Name, FromAgentID, string.Empty, IMSessionID, InstantMessageDialog.GroupInvitationAccept, InstantMessageOnline.Offline, Self.SimPosition, UUID.Zero, new byte[0]); found = groupName.IndexOf(":"); if (found > 0) { groupName = groupName.Substring(0, found).Trim(); ExecuteCommand("joingroup " + groupName, CMDFLAGS.NoResult); } } break; case InstantMessageDialog.InventoryOffered: break; case InstantMessageDialog.InventoryAccepted: break; case InstantMessageDialog.InventoryDeclined: break; case InstantMessageDialog.GroupVote: break; case InstantMessageDialog.TaskInventoryOffered: break; case InstantMessageDialog.TaskInventoryAccepted: break; case InstantMessageDialog.TaskInventoryDeclined: break; case InstantMessageDialog.NewUserDefault: break; case InstantMessageDialog.SessionAdd: break; case InstantMessageDialog.SessionOfflineAdd: break; case InstantMessageDialog.SessionGroupStart: break; case InstantMessageDialog.SessionCardlessStart: break; case InstantMessageDialog.SessionSend: break; case InstantMessageDialog.SessionDrop: break; case InstantMessageDialog.BusyAutoResponse: break; case InstantMessageDialog.ConsoleAndChatHistory: break; case InstantMessageDialog.Lure911: case InstantMessageDialog.RequestTeleport: if ((perms & BotPermissions.AcceptTeleport) != 0) { TheSimAvatar.StopMoving(); if (RegionID != UUID.Zero) { if (!displayedMessage) { DisplayNotificationInChat("TP to Lure from " + FromAgentName); displayedMessage = true; } SimRegion R = SimRegion.GetRegion(RegionID, gridClient); if (R != null) { Self.Teleport(R.RegionHandle, Position); return; } } DisplayNotificationInChat("Accepting TP Lure from " + FromAgentName); displayedMessage = true; Self.TeleportLureRespond(FromAgentID, IMSessionID, true); } break; case InstantMessageDialog.AcceptTeleport: break; case InstantMessageDialog.DenyTeleport: break; case InstantMessageDialog.GodLikeRequestTeleport: break; // case InstantMessageDialog.CurrentlyUnused: // break; case InstantMessageDialog.GotoUrl: break; case InstantMessageDialog.Session911Start: break; case InstantMessageDialog.FromTaskAsAlert: break; case InstantMessageDialog.GroupNotice: break; case InstantMessageDialog.GroupNoticeInventoryAccepted: break; case InstantMessageDialog.GroupNoticeInventoryDeclined: break; case InstantMessageDialog.GroupInvitationAccept: break; case InstantMessageDialog.GroupInvitationDecline: break; case InstantMessageDialog.GroupNoticeRequested: break; case InstantMessageDialog.FriendshipOffered: if ((perms & BotPermissions.AcceptGroupAndFriendRequests) != 0) { DisplayNotificationInChat("Accepting Friendship from " + FromAgentName); Friends.AcceptFriendship(FromAgentID, IMSessionID); displayedMessage = true; } break; case InstantMessageDialog.FriendshipAccepted: break; case InstantMessageDialog.FriendshipDeclined: break; case InstantMessageDialog.StartTyping: break; case InstantMessageDialog.StopTyping: break; case InstantMessageDialog.MessageFromObject: case InstantMessageDialog.MessageFromAgent: // message from self if (FromAgentName == GetName()) { return; } // message from system if (FromAgentName == "System") { return; } // message from others CommandInstance ci; if (Commands.TryGetValue("im", out ci)) { var whisper = ci.WithBotClient as Cogbot.Actions.Communication.ImCommand; if (whisper != null) { whisper.currentAvatar = FromAgentID; whisper.currentSession = IMSessionID; } } var cea = origin as ChatEventArgs; if ((perms & BotPermissions.ExecuteCommands) != 0) { OutputDelegate WriteLine; if (origin is InstantMessageEventArgs) { WriteLine = new OutputDelegate( (string text, object[] ps) => { string reply0 = DLRConsole.SafeFormat(text, ps); InstantMessage(FromAgentID, reply0, IMSessionID); }); } else { WriteLine = new OutputDelegate( (string text, object[] ps) => { string reply0 = DLRConsole.SafeFormat(text, ps); Talk(reply0, 0, Type); }); } string cmd = Message; CMDFLAGS needResult = CMDFLAGS.Console; if (cmd.StartsWith("cmcmd ")) { cmd = cmd.Substring(6); WriteLine(""); WriteLine(string.Format("invokecm='{0}'", cmd)); ClientManager.DoCommandAll(cmd, FromAgentID, WriteLine); } else if (cmd.StartsWith("cmd ")) { cmd = cmd.Substring(4); WriteLine(string.Format("invoke='{0}'", cmd)); var res = ExecuteCommand(cmd, FromAgentID, WriteLine, needResult); WriteLine("iresult='" + res + "'"); } else if (cmd.StartsWith("/") || cmd.StartsWith("@")) { cmd = cmd.Substring(1); WriteLine(""); WriteLine(string.Format("invoke='{0}'", cmd)); var res = ExecuteCommand(cmd, FromAgentID, WriteLine, needResult); WriteLine("iresult='" + res + "'"); } } if (cea != null && cea.AudibleLevel == ChatAudibleLevel.Barely) { return; } break; default: break; } //if (Dialog != InstantMessageDialog.MessageFromAgent && Dialog != InstantMessageDialog.MessageFromObject) { string debug = String.Format("{0} {1} {2} {3} {4} {5}: {6}", groupIM ? "GroupIM" : "IM", Dialog, Type, perms, FromAgentID, FromAgentName, Helpers.StructToString(origin)); if (!displayedMessage) { DisplayNotificationInChat(debug); displayedMessage = true; } } }