Example #1
0
        /// <summary>
        /// The route handler for the request, which removes the user and
        /// disconnects their Google+ account from this app.
        /// </summary>
        /// <param name="context">The request/response context.</param>
        public override void ProcessRequest(HttpContext context)
        {
            // User is signed in.
            User user = GetUser(context);

            if (user == null)
            {
                context.Response.StatusCode        = 401;
                context.Response.StatusDescription = "Unauthorized request";
            }
            else
            {
                // Remove the cached credentials.
                context.Session[Properties.Resources.CURRENT_USER_SESSION_KEY] = null;
                context.Response.Cookies.Clear();

                // Load the User object that is to be deleted from the model.
                PhotohuntContext db       = new PhotohuntContext();
                User             toRemove = db.Users.Find(user.id);

                // Clean up the user data by removing votes and friend edges.
                DisconnectHelper.RemoveFriendEdges(toRemove);
                DisconnectHelper.RemoveVotes(toRemove);

                db.SaveChanges();

                // Disconnect the user's account from this app.
                if (DisconnectHelper.DisconnectAccount(context, toRemove))
                {
                    context.Response.StatusCode = 200;
                    context.Response.Write("Successfully disconnected.");
                }
            }
        }
Example #2
0
        private static void StepGrind(ShipyardItem shipyardItem)
        {
            var            random           = new Random();
            float          grindAmount      = Server.Instance.Config.GrinderSpeedMultiplier * PluginSettings.Instance.GrindMultiplier;
            HashSet <long> grindersToRemove = new HashSet <long>();
            //shorten this to grid for convenience
            MyCubeGrid  grid       = shipyardItem.Grid;
            List <Task> blockTasks = new List <Task>();

            if (grid?.Physics == null || grid.Closed)
            {
                return;
            }

            if (grid.BlocksCount < 1)
            {
                return;
            }

            //do a raycast to see if the grinder can see the block we're assigning to it
            foreach (IMyCubeBlock listGrinder in shipyardItem.Tools)
            {
                blockTasks.Add(Task.Run(() =>
                {
                    DisconnectHelper localDisconnect = new DisconnectHelper();
                    MySlimBlock nextBlock;
                    if (!shipyardItem.ProcessBlocks.TryGetValue(listGrinder.EntityId, out nextBlock))
                    {
                        var tryCount = 0;

                        //TODO: optimize the try count instead of picking an arbitrary value
                        //what the hell does that mean?
                        while (tryCount < 30)
                        {
                            if (grid.Physics.LinearVelocity != Vector3D.Zero || grid.Physics.AngularVelocity != Vector3D.Zero)
                            {
                                grid.Stop();
                            }

                            //limit the number of tries so we don't get stuck in a loop forever
                            tryCount++;

                            //pick a random block. we don't really care if two grinders hit the same block, so don't check
                            if (grid.BlocksCount > 30)
                            {
                                nextBlock = grid.CubeBlocks.ElementAt(random.Next(0, grid.BlocksCount - 1));
                            }

                            //if we have less than 30 blocks total, just iterate through them, it's faster than going at random
                            else
                            {
                                nextBlock = grid.CubeBlocks.ElementAt(Math.Min(tryCount, grid.BlocksCount - 1));
                            }
                            if (nextBlock == null)
                            {
                                continue;
                            }

                            if (shipyardItem.ProcessBlocks.ContainsValue(nextBlock))
                            {
                                continue;
                            }

                            //this raycast should give us the grid location of the first block it hits
                            //we don't really care if it hits our random block, just grab whatever the grinder sees first
                            Vector3I?blockResult = grid.RayCastBlocks(listGrinder.GetPosition(),
                                                                      grid.GridIntegerToWorld(nextBlock.Position));
                            if (!blockResult.HasValue)
                            {
                                continue;
                            }

                            //TODO: remove this when my PR is merged
                            //check if removing this block will split the grid
                            if (localDisconnect.TryDisconnect(grid.GetCubeBlock(blockResult.Value)))
                            {
                                //UtilityPlugin.Log.Info( "detected split" );
                                continue;
                            }

                            nextBlock = grid.GetCubeBlock(blockResult.Value);

                            break;
                        }

                        //we weren't able to find a suitable block somehow, so skip this grinder for now
                        if (nextBlock == null)
                        {
                            return;
                        }

                        //we found a block to pair with our grinder, add it to the dictionary and carry on with destruction
                        lock (shipyardItem.ProcessBlocks)
                        {
                            shipyardItem.ProcessBlocks.Add(listGrinder.EntityId, nextBlock);
                        }
                    }
                }));
                if (blockTasks.Count >= 2)
                {
                }
            }
            Task.WaitAll(blockTasks.ToArray());
            blockTasks.Clear();
            var tmpItemList = new List <MyPhysicalInventoryItem>();

            foreach (IMyCubeBlock grinderBlock in shipyardItem.Tools)
            {
                var grinder = (IMyShipGrinder)grinderBlock;

                var         grinderInventory = (MyInventory)grinder.GetInventory(0);
                MySlimBlock block;

                if (!shipyardItem.ProcessBlocks.TryGetValue(grinderBlock.EntityId, out block))
                {
                    continue;
                }

                if (block?.CubeGrid?.Physics == null)
                {
                    continue;
                }

                if (disconnect.TryDisconnect(block))
                {
                    //UtilityPlugin.Log.Info( "detected split at grind" );
                    shipyardItem.ProcessBlocks.Remove(grinderBlock.EntityId);
                    continue;
                }

                Wrapper.GameAction(() =>
                {
                    var damageInfo = new MyDamageInformation(false, grindAmount, MyDamageType.Grind,
                                                             grinder.EntityId);
                    if (block.UseDamageSystem)
                    {
                        MyDamageSystem.Static.RaiseBeforeDamageApplied(block, ref damageInfo);
                    }

                    block.DecreaseMountLevel(damageInfo.Amount, grinderInventory);
                    block.MoveItemsFromConstructionStockpile(grinderInventory);
                    if (block.UseDamageSystem)
                    {
                        MyDamageSystem.Static.RaiseAfterDamageApplied(block, damageInfo);
                    }

                    if (block.IsFullyDismounted)
                    {
                        if (block.FatBlock != null && block.FatBlock.HasInventory)
                        {
                            for (var i = 0; i < block.FatBlock.InventoryCount; ++i)
                            {
                                MyInventory blockInventory = block.FatBlock.GetInventory(i);
                                if (blockInventory == null)
                                {
                                    continue;
                                }

                                if (blockInventory.Empty())
                                {
                                    continue;
                                }

                                tmpItemList.Clear();
                                tmpItemList.AddList(blockInventory.GetItems());

                                foreach (MyPhysicalInventoryItem item in tmpItemList)
                                {
                                    MyInventory.Transfer(blockInventory, grinderInventory, item.ItemId);
                                }
                            }
                        }

                        if (block.UseDamageSystem)
                        {
                            MyDamageSystem.Static.RaiseDestroyed(block, damageInfo);
                        }

                        block.SpawnConstructionStockpile();
                        block.CubeGrid.RazeBlock(block.Min);
                        grindersToRemove.Add(grinderBlock.EntityId);
                    }
                });
                foreach (var tool in shipyardItem.Tools)
                {
                    MySlimBlock targetBlock;
                    Communication.MessageStruct message = new Communication.MessageStruct()
                    {
                        toolId      = tool.EntityId,
                        gridId      = 0,
                        blockPos    = new SerializableVector3I(0, 0, 0),
                        packedColor = 0,
                        pulse       = false
                    };
                    if (!shipyardItem.ProcessBlocks.TryGetValue(tool.EntityId, out targetBlock))
                    {
                        Communication.SendLine(message);
                        continue;
                    }
                    message.gridId      = targetBlock.CubeGrid.EntityId;
                    message.blockPos    = targetBlock.Position;
                    message.packedColor = Color.OrangeRed.PackedValue;
                    Communication.SendLine(message);
                }

                foreach (long removeId in grindersToRemove)
                {
                    shipyardItem.ProcessBlocks.Remove(removeId);
                }
            }
        }
 public EmpoweredSubscriber(DisconnectWorker worker, DisconnectHelper helper)
 {
     _worker = worker;
     _helper = helper;
 }