Example #1
0
 public static NetDino ConvertDbDino(DbDino dino)
 {
     return(new NetDino
     {
         tribe_id = dino.tribe_id,
         dino_id = dino.dino_id.ToString(),
         is_female = dino.is_female,
         colors = new int[6],
         colors_hex = new string[6],
         tamed_name = dino.tamed_name,
         tamer_name = dino.tamer_name,
         classname = dino.classname,
         current_stats = dino.current_stats,
         max_stats = dino.max_stats,
         base_levelups_applied = dino.base_levelups_applied,
         tamed_levelups_applied = dino.tamed_levelups_applied,
         base_level = dino.base_level,
         level = dino.level,
         experience = dino.experience,
         is_baby = dino.is_baby,
         baby_age = dino.baby_age,
         next_imprint_time = dino.next_imprint_time,
         imprint_quality = dino.imprint_quality,
         location = dino.location,
         status = dino.status,
         taming_effectiveness = dino.taming_effectiveness,
         is_cryo = dino.is_cryo,
         experience_points = dino.experience_points,
         last_sync_time = dino.last_sync_time,
         is_alive = dino.is_alive,
         tribe_prefs = dino.prefs
     });
 }
Example #2
0
        public async Task DeleteServer(DeltaConnection conn)
        {
            //Delete this
            var filter = Builders <DbServer> .Filter.Eq("_id", this._id);

            await conn.system_servers.DeleteOneAsync(filter);

            //Delete content
            await DbTribe.DeleteServerContent(conn, this._id);

            await DbStructure.DeleteServerContent(conn, this._id);

            await DbInventory.DeleteServerContent(conn, this._id);

            await DbDino.DeleteServerContent(conn, this._id);

            await DbPlayerProfile.DeleteServerContent(conn, this._id);

            //Send Events
            conn.events.OnServerDeleted(this);
            //It's unimportant to notify user groups changed, as no further events will ever be sent from this server
        }
        public static DbDino QueueDino(List <WriteModel <DbDino> > dinoActions, DbServer server, string inventoryId, ulong revisionId, byte revisionIndex, int inventoryType, ulong inventoryItemId, string request)
        {
            //Parse the dino data
            DbDino dino = ParseDinoData(server, inventoryId, revisionId, revisionIndex, inventoryType, inventoryItemId, request);

            if (dino == null)
            {
                return(null);
            }

            //Enqueue adding this dino
            {
                //Create filter for updating this dino
                var filterBuilder = Builders <DbDino> .Filter;
                var filter        = filterBuilder.Eq("dino_id", dino.dino_id) & filterBuilder.Eq("server_id", server.id);

                //Now, add (or insert) this into the database
                var a = new ReplaceOneModel <DbDino>(filter, dino);
                a.IsUpsert = true;
                dinoActions.Add(a);
            }

            return(dino);
        }
 public static async Task RequestDinoUpdate(DeltaConnection conn, DbDino dino, ObjectId sender_id)
 {
     await RequestDinoUpdate(conn, dino.server_id, sender_id, dino.dino_id);
 }
        public static async Task OnHttpRequest(Microsoft.AspNetCore.Http.HttpContext e)
        {
            //Authenticate
            DbServer server = await Program.ForceAuthServer(e);

            if (server == null)
            {
                return;
            }

            //Decode
            RevisionMappedDataPutRequest <ItemData> request = Program.DecodeStreamAsJson <RevisionMappedDataPutRequest <ItemData> >(e.Request.Body);

            //Get primal data
            var pack = await Program.conn.GetPrimalDataPackage(server.mods);

            //Create queues
            List <WriteModel <DbDino> > dinoQueue = new List <WriteModel <DbDino> >();
            List <WriteModel <DbItem> > queue     = new List <WriteModel <DbItem> >();

            //Add items
            foreach (var i in request.data)
            {
                //Get parent ID
                string parentId = i.iid1.ToString();
                if (i.imp)
                {
                    parentId = Program.GetMultipartID((uint)i.iid1, (uint)i.iid2).ToString();
                }

                //Get item entry
                ItemEntry ientry = await pack.GetItemEntryByClssnameAsnyc(i.classname);

                if (ientry == null)
                {
                    continue;
                }

                //Convert
                DbItem item = new DbItem
                {
                    classname     = Program.TrimArkClassname(i.classname),
                    crafter_name  = "",
                    crafter_tribe = "",
                    is_blueprint  = false,
                    is_engram     = false,
                    item_id       = Program.GetMultipartID((uint)i.id1, (uint)i.id2),
                    last_durability_decrease_time = -1,
                    parent_id          = parentId,
                    parent_type        = (DbInventoryParentType)i.it,
                    saved_durability   = i.durability,
                    server_id          = server._id,
                    stack_size         = i.count,
                    tribe_id           = i.tribe,
                    revision_id        = request.revision_id,
                    revision_type      = request.revision_index,
                    entry_display_name = ientry.name
                };

                //Add cryo dino if this is one
                if (i.cryo != null)
                {
                    try
                    {
                        DbDino d = CryoStorageTool.QueueDino(dinoQueue, out DinosaurEntry entry, server, parentId, request.revision_id, request.revision_index, (int)item.parent_type, item.item_id, pack, i.cryo);
                        if (d != null)
                        {
                            item.custom_data_name  = "CRYOPOD";
                            item.custom_data_value = d.dino_id.ToString();
                        }
                    } catch (Exception ex)
                    {
                        Console.WriteLine("Failed to read cryo data: " + ex.Message);
                    }
                }

                //Add to queue
                InventoryManager.AddItemToQueue(queue, item);
            }

            //Apply updates
            await InventoryManager.UpdateInventoryItems(queue, Program.conn);

            if (dinoQueue.Count > 0)
            {
                await Program.conn.content_dinos.BulkWriteAsync(dinoQueue);

                dinoQueue.Clear();
            }
        }
        private static DbDino ParseDinoData(DbServer server, string inventoryId, ulong revisionId, byte revisionIndex, int inventoryType, ulong inventoryItemId, string request)
        {
            //Decode data as bytes and read
            byte[] data = new byte[request.Length / 2];
            for (int index = 0; index < data.Length; index++)
            {
                data[index] = byte.Parse(request.Substring(index * 2, 2), System.Globalization.NumberStyles.HexNumber);
            }

            //Now, decode and parse
            ARKDinoDataObject[] parts = ARKDinoDataTool.ReadData(data);
            Console.WriteLine(JsonConvert.SerializeObject(parts));

            //Get dino part
            ARKDinoDataObject d = parts[0];

            //Convert colors
            List <string> colors = new List <string>();

            for (int i = 0; true; i++)
            {
                ByteProperty colorProp = d.GetPropertyByName <ByteProperty>("ColorSetIndices", i);
                if (colorProp == null)
                {
                    break;
                }
                byte color = colorProp.byteValue;
                if (color <= 0 || color > ArkStatics.ARK_COLOR_IDS.Length)
                {
                    colors.Add("#FFFFFF");
                }
                else
                {
                    colors.Add(ArkStatics.ARK_COLOR_IDS[colorProp.byteValue - 1]); //Look this up in the color table to get the nice HTML value.
                }
            }

            //Get status component
            ARKDinoDataObject status = d.GetPropertyByName <ObjectProperty>("MyCharacterStatusComponent").localLinkObject;

            //Read as dino, adding required fields first
            DbDino dino = new DbDino
            {
                revision_id            = revisionId,
                revision_type          = revisionIndex,
                is_cryo                = true,
                cryo_inventory_id      = inventoryId,
                dino_id                = Program.GetMultipartID(d.GetPropertyByName <UInt32Property>("DinoID1").value, d.GetPropertyByName <UInt32Property>("DinoID2").value),
                tribe_id               = d.GetPropertyByName <IntProperty>("TargetingTeam").value,
                tamed_name             = d.GetStringProperty("TamedName", 0, ""),
                classname              = Program.TrimArkClassname(d.name),
                tamer_name             = d.GetStringProperty("TamerString", 0, ""),
                baby_age               = d.GetFloatProperty("BabyAge", 0, 1),
                is_baby                = d.GetBoolProperty("bIsBaby", 0, false),
                next_imprint_time      = d.GetDoubleProperty("BabyNextCuddleTime", 0, 0),
                imprint_quality        = d.GetFloatProperty("DinoImprintingQuality", 0, 0),
                color_indexes          = new int[6],
                experience             = status.GetFloatProperty("ExperiencePoints", 0, 0),
                server_id              = server._id,
                location               = new DbLocation(0, 0, 0),
                is_female              = d.GetBoolProperty("bIsFemale", 0, false),
                level                  = status.GetIntProperty("BaseCharacterLevel", 0, 0) + status.GetUInt16Property("ExtraCharacterLevel", 0, 0),
                base_level             = status.GetIntProperty("BaseCharacterLevel", 0, 0),
                is_tamed               = true,
                taming_effectiveness   = 1,
                max_stats              = ConvertStatsFloat(status, "MaxStatusValues"),
                current_stats          = ConvertStatsFloat(status, "CurrentStatusValues"),
                tamed_levelups_applied = ConvertStatsInt(status, "NumberOfLevelUpPointsAppliedTamed"),
                base_levelups_applied  = ConvertStatsInt(status, "NumberOfLevelUpPointsApplied"),
                status                 = ConvertStatus(d),
                cryo_inventory_type    = inventoryType,
                cryo_inventory_itemid  = inventoryItemId,
                experience_points      = status.GetFloatProperty("ExperiencePoints", 0, 0)
            };

            return(dino);
        }
Example #7
0
 public static ulong GetMultipartID(uint u1, uint u2)
 {
     return(DbDino.ZipperDinoId(u1, u2));
 }