Example #1
0
        public static void Initialise()
        {
            new Thread(() =>
            {
                var sw          = new Stopwatch();
                double lastTick = 0d;

                while (true)
                {
                    sw.Restart();

                    NetworkManager.Update(lastTick);
                    SocialManager.Update(lastTick);
                    MapManager.Update();

                    Thread.Sleep(1);
                    lastTick = (double)sw.ElapsedTicks / Stopwatch.Frequency;

                    #if DEBUG
                    Console.Title = $"{WorldServer.Title} (Update Time: {lastTick})";
                    #endif
                }
            })
            {
                IsBackground = true
            }.Start();
        }
Example #2
0
        private bool TrySaveSocialType(int profileId, SocialTypes socialType)
        {
            bool success = false;

            try
            {
                using (UserProfileDatabaseContext dbContext = new UserProfileDatabaseContext())
                {
                    // Get the SocialManager handle first
                    UserProfile   currentUser  = dbContext.UserProfiles.FirstOrDefault(u => u.UserName == User.Identity.Name);
                    SocialManager socialRecord = dbContext.SocialManager.Where(x => x.SocialType == socialType && x.User.Id == currentUser.Id).FirstOrDefault();
                    DateTime      currentTime  = DateTime.UtcNow;
                    int           days         = socialRecord != null ? ((TimeSpan)currentTime.Subtract((DateTime)socialRecord.TimeStamp)).Days : 0;
                    int?          socialId;

                    if (days <= ThresholdDays && socialRecord != null)
                    {
                        if (socialRecord.Count < ThresholdSocialTypeCount)
                        {
                            success = socialType == SocialTypes.Request ? TrySaveRequest(profileId, currentUser, dbContext, out socialId) : TrySaveMessage(profileId, currentUser, out socialId);
                            if (!success)
                            {
                                return(success);
                            }
                            socialRecord.Count++;
                            socialRecord.Update(dbContext);
                        }
                        else
                        {
                            // No. of counts exceeded for the given period.
                            success = false;
                        }
                    }
                    else
                    {
                        success = socialType == SocialTypes.Request ? TrySaveRequest(profileId, currentUser, dbContext, out socialId) : TrySaveMessage(profileId, currentUser, out socialId);
                        if (!success)
                        {
                            return(success);
                        }

                        if (socialRecord != null)
                        {
                            socialRecord.TimeStamp = DateTime.UtcNow;
                            socialRecord.SocialId  = socialId.GetValueOrDefault();
                            socialRecord.Count     = 1;
                            socialRecord.Update(dbContext);
                        }
                        else
                        {
                            SocialManager newSocialRecord = new SocialManager
                            {
                                User       = currentUser,
                                SocialId   = socialId.GetValueOrDefault(),
                                SocialType = socialType,
                                TimeStamp  = DateTime.UtcNow,
                                Count      = 1,
                            };

                            dbContext.SocialManager.Add(newSocialRecord);
                        }
                    }

                    dbContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Write("Operation failed with following ex : {0}", ex.ToString());

                return(false);
            }

            return(success);
        }