Ejemplo n.º 1
0
        public ListAddFailureEnum?CanAddFriend(WorldAccount friendAccount)
        {
            ListAddFailureEnum?result;

            if (friendAccount.Id == this.Owner.Client.WorldAccount.Id)
            {
                result = new ListAddFailureEnum?(ListAddFailureEnum.LIST_ADD_FAILURE_EGOCENTRIC);
            }
            else
            {
                if (this.m_friends.ContainsKey(friendAccount.Id))
                {
                    result = new ListAddFailureEnum?(ListAddFailureEnum.LIST_ADD_FAILURE_IS_DOUBLE);
                }
                else
                {
                    if (this.m_friends.Count >= FriendsBook.MaxFriendsNumber)
                    {
                        result = new ListAddFailureEnum?(ListAddFailureEnum.LIST_ADD_FAILURE_OVER_QUOTA);
                    }
                    else
                    {
                        result = null;
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
 public Ignored(AccountRelation relation, WorldAccount account, bool session, Character character)
 {
     Relation  = relation;
     Session   = session;
     Account   = account;
     Character = character;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Called after LoadSEconomy, or on PostInitialize, this binds the current SEconomy instance
        /// to the currently running terraria world.
        /// </summary>
        public async Task BindToWorldAsync()
        {
            IBankAccount account = null;

            if ((WorldAccount = RunningJournal.GetWorldAccount()) == null)
            {
                TShock.Log.ConsoleError("[SEconomy Bind] The journal system did not return a world account. This is an internal error.");
                return;
            }

            await WorldAccount.SyncBalanceAsync();

            TShock.Log.ConsoleInfo(string.Format(SEconomyPlugin.Locale.StringOrDefault(1, "[SEconomy World Account] Paid {0} to players."), WorldAccount.Balance.ToLongString()));

            await Task.Delay(5000);

            foreach (var player in TShockAPI.TShock.Players)
            {
                if (player == null ||
                    string.IsNullOrWhiteSpace(player.Name) == true
                    //|| string.IsNullOrWhiteSpace(player.User.Name) == true
                    || (account = GetBankAccount(player)) == null)
                {
                    continue;
                }

                await account.SyncBalanceAsync();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Occurs when a player online payment needs to occur.
        /// </summary>
        void PayRunTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            lock (__accountSafeLock) {
                if (Configuration.PayIntervalMinutes > 0 && !string.IsNullOrEmpty(Configuration.IntervalPayAmount))
                {
                    Money payAmount;

                    if (Money.TryParse(Configuration.IntervalPayAmount, out payAmount))
                    {
                        if (payAmount > 0)
                        {
                            foreach (Economy.EconomyPlayer ep in economyPlayers)
                            {
                                //if the time since the player was idle is less than or equal to the configuration idle threshold
                                //then the player is considered not AFK.
                                if (ep.TimeSinceIdle.TotalMinutes <= Configuration.IdleThresholdMinutes && ep.BankAccount != null)
                                {
                                    //Pay them from the world account
                                    WorldAccount.TransferToAsync(ep.BankAccount, payAmount, Journal.BankAccountTransferOptions.AnnounceToReceiver);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
 public Ignored(AccountRelation relation, WorldAccount account, bool session, Character character)
 {
     this.Relation  = relation;
     this.Session   = session;
     this.Account   = account;
     this.Character = character;
 }
Ejemplo n.º 6
0
        public static void HandleIgnoredAddRequestMessage(WorldClient client, IgnoredAddRequestMessage message)
        {
            Character character = Singleton <World> .Instance.GetCharacter(message.name);

            if (character != null)
            {
                if (character.UserGroup.Role == RoleEnum.Player)
                {
                    client.Character.FriendsBook.AddIgnored(character.Client.WorldAccount, message.session);
                }
                else
                {
                    FriendHandler.SendFriendAddFailureMessage(client, ListAddFailureEnum.LIST_ADD_FAILURE_NOT_FOUND);
                }
            }
            else
            {
                ServerBase <WorldServer> .Instance.IOTaskPool.AddMessage(delegate
                {
                    WorldAccount record = Singleton <AccountManager> .Instance.FindByNickname(message.name);
                    if (record != null && client.Character.Context != null)
                    {
                        client.Character.Context.ExecuteInContext(delegate
                        {
                            client.Character.FriendsBook.AddIgnored(record, message.session);
                        });
                    }
                    else
                    {
                        FriendHandler.SendIgnoredAddFailureMessage(client, ListAddFailureEnum.LIST_ADD_FAILURE_NOT_FOUND);
                    }
                });
            }
        }
Ejemplo n.º 7
0
        public IEnumerable <Merchant> UnActiveMerchantFromAccount(WorldAccount account)
        {
            var merchants = m_activeMerchants.Where(x => x.IsMerchantOwner(account)).ToArray();

            foreach (var merchant in merchants)
            {
                UnActiveMerchant(merchant);
                yield return(merchant);
            }
        }
Ejemplo n.º 8
0
        public WorldAccount CreateWorldAccount(WorldClient client)
        {
            WorldAccount worldAccount = new WorldAccount
            {
                Id       = client.Account.Id,
                Nickname = client.Account.Nickname
            };

            base.Database.Insert(worldAccount);
            return(worldAccount);
        }
Ejemplo n.º 9
0
        public bool AddFriend(WorldAccount friendAccount)
        {
            var result = CanAddFriend(friendAccount);

            if (result != null)
            {
                FriendHandler.SendFriendAddFailureMessage(Owner.Client, result.Value);
                return(false);
            }

            var relation = new AccountRelation
            {
                AccountId = Owner.Client.Account.Id,
                TargetId  = friendAccount.Id,
                Type      = AccountRelationType.Friend
            };

            m_relations.AddOrUpdate(relation.TargetId, relation, (key, value) =>
            {
                value.Type = AccountRelationType.Friend;
                return(value);
            });

            Friend friend;
            var    isConnected = friendAccount.ConnectedCharacter.HasValue;

            if (isConnected)
            {
                var character = World.Instance.GetCharacter(friendAccount.ConnectedCharacter.Value);
                friend = new Friend(relation, friendAccount, character);
            }
            else
            {
                friend = new Friend(relation, friendAccount);
            }

            var success = m_friends.TryAdd(friendAccount.Id, friend);

            if (success && isConnected)
            {
                OnFriendOnline(friend);
            }
            else
            {
                friend.SetOffline();
            }

            FriendHandler.SendFriendAddedMessage(Owner.Client, friend);

            return(success);
        }
        private static void OnAccountReceived(AccountAnswerMessage message, WorldClient client)
        {
            lock (ApproachHandler.ConnectionQueue.SyncRoot)
            {
                ApproachHandler.ConnectionQueue.Remove(client);
            }
            if (client.QueueShowed)
            {
                ApproachHandler.SendQueueStatusMessage(client, 0, 0);
            }
            AccountData account = message.Account;

            if (account == null)
            {
                client.Send(new AuthenticationTicketRefusedMessage());
                client.DisconnectLater(1000);
            }
            else
            {
                WorldAccount worldAccount = Singleton <AccountManager> .Instance.FindById(account.Id);

                if (worldAccount != null)
                {
                    client.WorldAccount = worldAccount;
                    if (client.WorldAccount.ConnectedCharacter.HasValue)
                    {
                        Character character = Singleton <World> .Instance.GetCharacter(client.WorldAccount.ConnectedCharacter.Value);

                        if (character != null)
                        {
                            character.LogOut();
                        }
                    }
                }

                client.SetCurrentAccount(account);
                client.Send(new AuthenticationTicketAcceptedMessage());

                BasicHandler.SendBasicTimeMessage(client);
                ApproachHandler.SendServerOptionalFeaturesMessage(client, new sbyte[1] {
                    7
                });
                ApproachHandler.SendAccountCapabilitiesMessage(client);
                client.Send(new TrustStatusMessage(true, false));
                if (client.UserGroup.Role >= RoleEnum.Moderator)
                {
                    ApproachHandler.SendConsoleCommandsListMessage(client);
                }
            }
        }
Ejemplo n.º 11
0
        public WorldAccount CreateWorldAccount(WorldClient client)
        {
            /* Create WorldAccount */
            var worldAccount = new WorldAccount
            {
                Id        = client.Account.Id,
                Nickname  = client.Account.Nickname,
                Tokens    = 0,
                NewTokens = 0
            };

            Database.Insert(worldAccount);

            return(worldAccount);
        }
Ejemplo n.º 12
0
        public void Load()
        {
            this.m_relations = new ConcurrentDictionary <int, AccountRelation>(ServerBase <WorldServer> .Instance.DBAccessor.Database.Query <AccountRelation>(string.Format(AccountRelationRelator.FetchByAccount, this.Owner.Account.Id), new object[0]).ToDictionary((AccountRelation x) => x.AccountId, (AccountRelation x) => x));
            foreach (AccountRelation current in this.m_relations.Values)
            {
                WorldAccount worldAccount = Singleton <World> .Instance.GetConnectedAccount(current.TargetId) ?? Singleton <AccountManager> .Instance.FindById(current.TargetId);

                if (worldAccount == null)
                {
                    ServerBase <WorldServer> .Instance.DBAccessor.Database.Delete(current);
                }
                else
                {
                    switch (current.Type)
                    {
                    case AccountRelationType.Friend:
                        if (worldAccount.ConnectedCharacter.HasValue)
                        {
                            Character character = Singleton <World> .Instance.GetCharacter(worldAccount.ConnectedCharacter.Value);

                            this.m_friends.TryAdd(worldAccount.Id, new Friend(current, worldAccount, character));
                        }
                        else
                        {
                            this.m_friends.TryAdd(worldAccount.Id, new Friend(current, worldAccount));
                        }
                        break;

                    case AccountRelationType.Ignored:
                        if (worldAccount.ConnectedCharacter.HasValue)
                        {
                            Character character = Singleton <World> .Instance.GetCharacter(worldAccount.ConnectedCharacter.Value);

                            this.m_ignoreds.TryAdd(worldAccount.Id, new Ignored(current, worldAccount, false, character));
                        }
                        else
                        {
                            this.m_ignoreds.TryAdd(worldAccount.Id, new Ignored(current, worldAccount, false));
                        }
                        break;
                    }
                }
            }
            Singleton <World> .Instance.CharacterJoined += new System.Action <Character>(this.OnCharacterLogIn);
        }
Ejemplo n.º 13
0
        public bool AddIgnored(WorldAccount ignoredAccount, bool session = false)
        {
            var result = CanAddIgnored(ignoredAccount);

            if (result != null)
            {
                FriendHandler.SendIgnoredAddFailureMessage(Owner.Client, result.Value);
                return(false);
            }

            var relation = new AccountRelation
            {
                AccountId = Owner.Client.Account.Id,
                TargetId  = ignoredAccount.Id,
                Type      = AccountRelationType.Ignored
            };

            if (!session)
            {
                m_relations.AddOrUpdate(relation.TargetId, relation, (key, value) =>
                {
                    value.Type = AccountRelationType.Ignored;
                    return(value);
                });
            }

            Ignored ignored;

            if (ignoredAccount.ConnectedCharacter.HasValue)
            {
                var character = World.Instance.GetCharacter(ignoredAccount.ConnectedCharacter.Value);
                ignored = new Ignored(relation, ignoredAccount, session, character);
            }
            else
            {
                ignored = new Ignored(relation, ignoredAccount, session);
            }

            var success = m_ignoreds.TryAdd(ignoredAccount.Id, ignored);

            FriendHandler.SendIgnoredAddedMessage(Owner.Client, ignored, session);

            return(success);
        }
Ejemplo n.º 14
0
        public bool AddFriend(WorldAccount friendAccount)
        {
            ListAddFailureEnum?listAddFailureEnum = this.CanAddFriend(friendAccount);
            bool result;

            if (listAddFailureEnum.HasValue)
            {
                FriendHandler.SendFriendAddFailureMessage(this.Owner.Client, listAddFailureEnum.Value);
                result = false;
            }
            else
            {
                AccountRelation accountRelation = new AccountRelation
                {
                    AccountId = this.Owner.Client.Account.Id,
                    TargetId  = friendAccount.Id,
                    Type      = AccountRelationType.Friend
                };
                this.m_relations.AddOrUpdate(accountRelation.TargetId, accountRelation, delegate(int key, AccountRelation value)
                {
                    value.Type = AccountRelationType.Friend;
                    return(value);
                });
                bool flag;
                if (friendAccount.ConnectedCharacter.HasValue)
                {
                    Character character = Singleton <World> .Instance.GetCharacter(friendAccount.ConnectedCharacter.Value);

                    Friend friend = new Friend(accountRelation, friendAccount, character);
                    if (flag = this.m_friends.TryAdd(friendAccount.Id, friend))
                    {
                        this.OnFriendOnline(friend);
                    }
                }
                else
                {
                    flag = this.m_friends.TryAdd(friendAccount.Id, new Friend(accountRelation, friendAccount));
                }
                FriendHandler.SendFriendsListMessage(this.Owner.Client, this.Friends);
                result = flag;
            }
            return(result);
        }
Ejemplo n.º 15
0
        ListAddFailureEnum?CanAddFriend(WorldAccount friendAccount)
        {
            if (friendAccount.Id == Owner.Client.WorldAccount.Id)
            {
                return(ListAddFailureEnum.LIST_ADD_FAILURE_EGOCENTRIC);
            }

            if (IsIgnored(friendAccount.Id) || IsFriend(friendAccount.Id))
            {
                return(ListAddFailureEnum.LIST_ADD_FAILURE_IS_DOUBLE);
            }

            if (m_friends.Count >= MaxFriendsNumber)
            {
                return(ListAddFailureEnum.LIST_ADD_FAILURE_OVER_QUOTA);
            }

            return(null);
        }
Ejemplo n.º 16
0
        public bool AddIgnored(WorldAccount ignoredAccount, bool session = false)
        {
            ListAddFailureEnum?listAddFailureEnum = this.CanAddIgnored(ignoredAccount);
            bool result;

            if (listAddFailureEnum.HasValue)
            {
                FriendHandler.SendIgnoredAddFailureMessage(this.Owner.Client, listAddFailureEnum.Value);
                result = false;
            }
            else
            {
                AccountRelation accountRelation = new AccountRelation
                {
                    AccountId = this.Owner.Client.Account.Id,
                    TargetId  = ignoredAccount.Id,
                    Type      = AccountRelationType.Ignored
                };
                if (!session)
                {
                    this.m_relations.AddOrUpdate(accountRelation.TargetId, accountRelation, delegate(int key, AccountRelation value)
                    {
                        value.Type = AccountRelationType.Ignored;
                        return(value);
                    });
                }
                bool flag;
                if (ignoredAccount.ConnectedCharacter.HasValue)
                {
                    Character character = Singleton <World> .Instance.GetCharacter(ignoredAccount.ConnectedCharacter.Value);

                    flag = this.m_ignoreds.TryAdd(ignoredAccount.Id, new Ignored(accountRelation, ignoredAccount, session, character));
                }
                else
                {
                    flag = this.m_ignoreds.TryAdd(ignoredAccount.Id, new Ignored(accountRelation, ignoredAccount, session));
                }
                FriendHandler.SendIgnoredListMessage(this.Owner.Client, this.Ignoreds);
                result = flag;
            }
            return(result);
        }
Ejemplo n.º 17
0
 public bool IsMerchantOwner(WorldAccount account)
 {
     return(account.Id == this.m_record.AccountId);
 }
        public System.Collections.Generic.IEnumerable <Merchant> UnActiveMerchantFromAccount(WorldAccount account)
        {
            var merchants = m_activeMerchants.Where(entry => entry.IsMerchantOwner(account)).ToArray();

            foreach (Merchant merchant in merchants)
            {
                this.UnActiveMerchant(merchant);
                yield return(merchant);
            }
        }
Ejemplo n.º 19
0
 public Ignored(AccountRelation relation, WorldAccount account, bool session)
 {
     Relation = relation;
     Session  = session;
     Account  = account;
 }
Ejemplo n.º 20
0
        public void UnBlockAccount(WorldAccount account)
        {
            Tuple <Character, DateTime> dummy;

            m_blockedAccount.TryRemove(account.Id, out dummy);
        }
Ejemplo n.º 21
0
 // block this account
 public void BlockAccount(WorldAccount account, Character character)
 {
     m_blockedAccount.TryAdd(account.Id, Tuple.Create(character, DateTime.Now));
 }
Ejemplo n.º 22
0
 public bool IsMerchantOwner(WorldAccount account) => account.Id == m_record.AccountId;
Ejemplo n.º 23
0
 public Friend(AccountRelation relation, WorldAccount account)
 {
     this.Relation = relation;
     this.Account  = account;
 }
Ejemplo n.º 24
0
 public Friend(AccountRelation relation, WorldAccount account)
 {
     Relation = relation;
     Account  = account;
 }
Ejemplo n.º 25
0
 public Friend(AccountRelation relation, WorldAccount account, Character character)
 {
     Relation  = relation;
     Account   = account;
     Character = character;
 }
Ejemplo n.º 26
0
 public Friend(AccountRelation relation, WorldAccount account, Character character)
 {
     this.Relation  = relation;
     this.Account   = account;
     this.Character = character;
 }
Ejemplo n.º 27
0
 public Ignored(AccountRelation relation, WorldAccount account, bool session)
 {
     this.Relation = relation;
     this.Session  = session;
     this.Account  = account;
 }