Пример #1
0
    private IEnumerator LoadAndTellPosition(object[] param)
    {
        NetworkPlayer player = (NetworkPlayer)param[0];
        String        id     = param[1] as String;

        Debug.Log("Started player load Coroutine for id: " + id);

        Unturned.Entity.Player plr = Database.provider.LoadPlayer(id);
        yield return(plr);

        try {
            Debug.Log("Coroutine received player data for id: " + id);

            if (plr.PositionX == 0 && plr.PositionY == 0)
            {
                loadPositionFromSerial(player, String.Empty);
            }
            else
            {
                Debug.Log("Sending tellPosition to player...");
                base.networkView.RPC("tellPosition", player, new object[] {
                    new Vector3(plr.PositionX, plr.PositionY, plr.PositionZ),
                    plr.ViewDirection
                });
            }
        }
        catch
        {
            Debug.Log("Exception in loader coroutine: " + id + " Client dropped!");
            Network.CloseConnection(player, false);
        }
    }
Пример #2
0
    private IEnumerator LoadPlayerFromDatabase()
    {
#if DEBUG
        Console.WriteLine("Requesting player from db: " + owner.id);
        long startTime = DateTime.Now.Millisecond;
#endif
        Unturned.Entity.Player plr = Database.provider.LoadPlayer(owner.id);
        yield return(plr);

#if DEBUG
        Console.WriteLine("Loaded player " + owner.id + " in " + (DateTime.Now.Millisecond - startTime) + "ms");
#endif

        TellLoaded(plr);
    }
Пример #3
0
    private IEnumerator GetRepuAndLogin(object[] param)
    {
        Unturned.Entity.Player plr = null;
        int repu = 0;

        String id = param[3] as String;
        Thread playerLoadThread = new Thread(delegate() {
            plr = Database.provider.LoadPlayer(id);
        });

        playerLoadThread.Start();

        while (plr == null && playerLoadThread.IsAlive)
        {
            yield return(null);
        }

        if (plr == null)
        {
            Console.WriteLine("Thread ended, but no user loaded.. WTF?!");
        }
        else
        {
            repu = plr.Reputation;
        }

        base.networkView.RPC("addNetworkUser", RPCMode.All, new object[] {
            param[0],
            param[1],
            param[2],
            param[3],
            param[4],
            repu,
            param[6]
        });

        yield return(plr);
    }
Пример #4
0
    private void TellLoaded(Unturned.Entity.Player plr)
    {
                #if DEBUG
        Console.WriteLine("Loading inventory...");
                #endif

        // Clothes
        Clothes clothes = GetComponent <Clothes>();
        clothes.item  = -1;
        clothes.state = string.Empty;
        clothes.networkView.RPC("tellAllClothes", RPCMode.All, new object[] {
            clothes.face,
            plr.Clothes.Shirt,
            plr.Clothes.Pants,
            plr.Clothes.Hat,
            clothes.hair,
            plr.Clothes.Backpack,
            plr.Clothes.Vest,
            clothes.item,
            clothes.state,
            clothes.skinColor,
            clothes.hairColor,
            clothes.arm
        });
        clothes.loaded = true;
        if (!clothes.networkView.isMine)
        {
            clothes.networkView.RPC("tellLoadedClothes", base.networkView.owner, new object[] { true });
        }

                #if DEBUG
        Console.WriteLine("Loading inventory...");
                #endif
        // Inventory
        Inventory inventory = GetComponent <Inventory>();
        inventory.resize(plr.Inventory.Width, plr.Inventory.Height, plr.Inventory.Capacity);

        foreach (InventoryItem item in plr.Inventory.Items)
        {
            inventory.items[item.X, item.Y] = new ClientItem(
                item.ItemID,
                item.Amount,
                item.State);
        }

        inventory.UpdateItems();
        inventory.syncWeight();
        inventory.loaded = true;
        if (!inventory.networkView.isMine)
        {
            inventory.networkView.RPC("tellLoadedInventory", base.networkView.owner, new object[] { true });
        }

                #if DEBUG
        Console.WriteLine("Loading skills...");
                #endif
        // Skills
        Skills skills = GetComponent <Skills>();
        skills.loadAllKnowledgeFromSerial(plr.Skills.Experience + ";" + plr.Skills.Skills);

                #if DEBUG
        Console.WriteLine("Loading life...");
                #endif
        // Life
        Life life = GetComponent <Life>();
        life.bleeding = plr.Life.Bleeding;
        life.bones    = plr.Life.BrokenBones;

        life.health   = plr.Life.Health;
        life.water    = plr.Life.Water;
        life.food     = plr.Life.Food;
        life.sickness = plr.Life.Sickness;

        life.FixStats();
        life.FinalizeLoad();
    }
Пример #5
0
    public void save()
    {
        if (false)             // TODO: implement config manager
        {
            this.saveAllOrientation();
            base.GetComponent <Inventory>().saveAllItems();
            base.GetComponent <Clothes>().saveAllClothing();
            base.GetComponent <Life>().saveAllVitality();
            base.GetComponent <Skills>().saveAllKnowledge();
            PlayerPrefs.Save();
        }
        else
        {               // Remote database woooh :P
#if DEBUG
            Console.WriteLine("Saving player: " + this.name);
#endif
            var plr = new Unturned.Entity.Player();
            plr.Reputation    = owner.reputation;
            plr.SteamID       = owner.id;
            plr.Name          = name;
            plr.PositionX     = transform.position.x;
            plr.PositionY     = transform.position.y;
            plr.PositionZ     = transform.position.z;
            plr.ViewDirection = transform.rotation.eulerAngles.y;

#if DEBUG
            Console.WriteLine("Serializing inventory");
#endif

            // Inventory
            Inventory inv = GetComponent <Inventory>();
            plr.Inventory       = new PlayerInventory(inv.height, inv.width, inv.capacity);
            plr.Inventory.Items = new List <InventoryItem>();

            for (int i = 0; i < inv.height; i++)
            {
                for (int j = 0; j < inv.width; j++)
                {
                    ClientItem item = inv.items[j, i];
                    if (item.id != -1)
                    {
                        plr.Inventory.Items.Add(new InventoryItem(item.id, item.amount, item.state, j, i));
                    }
                }
            }

#if DEBUG
            Console.WriteLine("Serializing Clothes");
#endif

            // Clothes
            Clothes cloth = GetComponent <Clothes>();
            plr.Clothes = new PlayerClothes(
                cloth.shirt,
                cloth.pants,
                cloth.hat,
                cloth.backpack,
                cloth.vest);
#if DEBUG
            Console.WriteLine("Serializing Life");
#endif

            // Life
            Life life = GetComponent <Life>();
            plr.Life = new PlayerLife(
                life.health,
                life.food,
                life.water,
                life.sickness,
                life.bleeding,
                life.bones);

#if DEBUG
            Console.WriteLine("Serializing Skills");
#endif

            // Skills
            Skills skills = GetComponent <Skills>();
            plr.Skills            = new PlayerSkills();
            plr.Skills.Experience = skills.experience;

            String skillLine = "";
            for (int j = 0; j < (int)skills.skills.Length; j++)
            {
                skillLine = string.Concat(skillLine, skills.skills[j].level, ";");
            }
            plr.Skills.Skills = skillLine;

#if DEBUG
            Console.WriteLine("Writing player to file");
#endif
            Database.provider.SavePlayer(plr);
            plr = null;
        }
    }