private void MakeBenchData()
    {
        var random = new Random();

        for (int i = 1; i < 512; i++)
        {
            benchKeys.Add((uint)i);
            var stream = NetStream.New();
            for (int f = 0; f < 128; f++)
            {
                stream.WriteInt(random.Next());
            }
            benchStream.Add(stream);
        }
    }
Example #2
0
    void CreateCharacter(string playerName, NetConnection connection)
    {
        if (!InputValidator.LowercaseOnly(playerName))
        {
            return;
        }
        LoginServer.Account account;
        if (!loginServer.TryGetAccount(connection, out account))
        {
            return;
        }
        if (database.HasKey(playerName))
        {
            socket.Send("NameTakenResponse", connection);
            return;
        }

        NetStream playerData = NetStream.New();

        playerData.WriteString(playerName);
        playerData.WriteInt(100);
        playerData.WriteVector3(Vector3.zero);

        ulong key;

        if (!database.TryAdd(playerName, playerData, out key))
        {
            return;
        }
        if (!AddCharacterNameKey(key, account.Id))
        {
            database.TryDelete(key);
            playerData.Release();
            return;
        }
        playerData.Position = 0;
        viewManager.CreateView(connection, "Player", playerData);
    }
Example #3
0
    bool AddCharacterNameKey(ulong characterKey, ulong accountId)
    {
        string    charnamesKey = accountId + "_chars";
        NetStream namesStream;

        if (database.TryGet(charnamesKey, out namesStream))
        {
            for (int i = 0; i < 4; i++)
            {
                try {
                    if (namesStream.ReadULong() == 0)
                    {
                        namesStream.Position = namesStream.Position - 64;
                        break;
                    }
                    if (i == 3)
                    {
                        return(false);
                    }
                } catch {
                    if (i == 3)
                    {
                        return(false);        // Already has 4 characters
                    }
                    break;
                }
            }
            namesStream.WriteULong(characterKey);
            return(database.TryUpdate(charnamesKey, namesStream));
        }
        else
        {
            namesStream = NetStream.New();
            namesStream.WriteULong(characterKey);
            ulong namesKey;
            return(database.TryAdd(charnamesKey, namesStream, out namesKey));
        }
    }