Esempio n. 1
0
 protected void OnEnable()
 {
     this.SetLocalOnlyComponentsEnabled(true);
     LockCursorManager.IsLocked(true);
     this.onceClock = false;
     this.clock     = SystemTimestamp.Restart;
 }
Esempio n. 2
0
        private int SendAll(ArraySegment <byte> buffer, int microsLeft)
        {
            var array  = buffer.Array;
            var offset = buffer.Offset;
            var left   = buffer.Count; // how many bytes left to send

            while (left > 0)
            {
                var startTimestamp = SystemTimestamp.Current;
                var sent           = Socket.Send(array, offset, left, microsLeft);
                var elapsedMicros  = SystemTimestamp.GetElapsedMicros(startTimestamp);

                offset     += sent;
                left       -= sent;
                microsLeft -= elapsedMicros;
            }

            return(microsLeft);
        }
Esempio n. 3
0
 protected void Update()
 {
     if (!base.dead)
     {
         try
         {
             this.UpdateInput();
         }
         finally
         {
             if ((!this.onceClock || (this.clock.ElapsedSeconds > NetCull.sendInterval)) && !base.dead)
             {
                 this.onceClock = true;
                 this.SendToServer();
                 this.clock = SystemTimestamp.Restart;
             }
         }
     }
 }
Esempio n. 4
0
        private void ReceiveAll(ArraySegment <byte> buffer, int microsLeft)
        {
            var array   = buffer.Array;
            var offset  = buffer.Offset;
            var maxSize = buffer.Count;

            var totalReceived = 0;

            while (!_messageComplete)
            {
                var startTimestamp = SystemTimestamp.Current;
                var read           = Socket.Receive(array, offset,
                                                    maxSize - totalReceived, microsLeft);
                var elapsedMicros = SystemTimestamp.GetElapsedMicros(startTimestamp);

                _parser.Execute(new ArraySegment <byte>(array, offset, read));

                offset        += read;
                totalReceived += read;
                microsLeft    -= elapsedMicros;
            }
        }
Esempio n. 5
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (Payload != null ? Payload.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (EmitterId != null ? EmitterId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (EmitterAggregateId != null ? EmitterAggregateId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ SystemTimestamp.GetHashCode();
         hashCode = (hashCode * 397) ^ (VectorTimestamp != null ? VectorTimestamp.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ProcessId != null ? ProcessId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (LocalLogId != null ? LocalLogId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ LocalSequenceNr.GetHashCode();
         hashCode = (hashCode * 397) ^ (DeliveryId != null ? DeliveryId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ PersistOnEventSequenceNr.GetHashCode();
         hashCode = (hashCode * 397) ^ PersistOnEventId.GetHashCode();
         hashCode = (hashCode * 397) ^ Id.GetHashCode();
         foreach (var id in CustomDestinationAggregateIds)
         {
             hashCode = (hashCode * 397) ^ id.GetHashCode();
         }
         return(hashCode);
     }
 }
Esempio n. 6
0
 public bool Equals(DurableEvent other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(Payload, other.Payload) &&
            LocalSequenceNr == other.LocalSequenceNr &&
            string.Equals(EmitterId, other.EmitterId) &&
            string.Equals(EmitterAggregateId, other.EmitterAggregateId) &&
            CustomDestinationAggregateIds.SetEquals(other.CustomDestinationAggregateIds) &&
            SystemTimestamp.Equals(other.SystemTimestamp) &&
            Equals(VectorTimestamp, other.VectorTimestamp) &&
            string.Equals(ProcessId, other.ProcessId) &&
            string.Equals(LocalLogId, other.LocalLogId) &&
            string.Equals(DeliveryId, other.DeliveryId) &&
            PersistOnEventSequenceNr == other.PersistOnEventSequenceNr &&
            PersistOnEventId.Equals(other.PersistOnEventId) &&
            Id.Equals(other.Id));
 }
Esempio n. 7
0
 private Timer(SystemTimestamp clock)
 {
     this.clock = clock;
 }
Esempio n. 8
0
 public static void DoProcessUsers()
 {
     if (!Events.bool_1)
     {
         Events.bool_1 = true;
         foreach (UserData current in Users.All)
         {
             NetUser netUser = NetUser.FindByUserID(current.SteamID);
             if (netUser != null && !netUser.did_join)
             {
                 netUser = null;
             }
             List <Countdown> list = new List <Countdown>();
             foreach (Countdown current2 in Users.CountdownList(current.SteamID))
             {
                 if (current2.Expires)
                 {
                     if (current2.Expired)
                     {
                         list.Add(current2);
                     }
                     else if (current2.Command.Equals("pvp", StringComparison.OrdinalIgnoreCase) && current.HasFlag(UserFlags.nopvp) && Convert.ToInt32(current2.TimeLeft) < Core.CommandNoPVPCountdown)
                     {
                         current.SetFlag(UserFlags.nopvp, false);
                         if (netUser != null)
                         {
                             Broadcast.Notice(netUser, "☢", Config.GetMessage("Command.PvP.Enabled", netUser, null), 5f);
                         }
                         Broadcast.NoticeAll("☢", Config.GetMessage("Command.PvP.NoticeEnabled", null, current.Username), netUser, 5f);
                     }
                 }
             }
             foreach (Countdown current3 in list)
             {
                 Users.CountdownRemove(current.SteamID, current3);
             }
             if (current.PremiumDate.Millisecond != 0 && current.PremiumDate < DateTime.Now)
             {
                 Users.SetFlags(current.SteamID, UserFlags.premium, false);
                 Users.SetRank(current.SteamID, Users.DefaultRank);
                 Users.SetPremiumDate(current.SteamID, default(DateTime));
                 Broadcast.Notice(netUser, "☢", Config.GetMessage("Player.Premium.Expired", null, null), 5f);
             }
             if (Core.OwnershipDestroyAutoDisable > 0 && Core.DestoryOwnership.ContainsKey(current.SteamID) && Core.DestoryOwnership[current.SteamID] < DateTime.Now)
             {
                 Core.DestoryOwnership.Remove(current.SteamID);
                 if (netUser != null)
                 {
                     Broadcast.Notice(netUser, "☢", Config.GetMessage("Command.Destroy.Disabled", null, null), 5f);
                 }
             }
             Character character;
             if (netUser != null && netUser.did_join && netUser.admin && Character.FindByUser(netUser.userID, out character))
             {
                 Metabolism component = character.GetComponent <Metabolism>();
                 if (component.GetCalorieLevel() < 3000f)
                 {
                     component.AddCalories(3000f - component.GetCalorieLevel());
                 }
                 if (component.GetRadLevel() > 0f)
                 {
                     component.AddAntiRad(component.GetRadLevel());
                 }
             }
         }
         Events.bool_1 = false;
         if (Core.DatabaseType.Equals("MYSQL") && !Events.bool_3 && DateTime.Now.Subtract(Events.dateTime_0).TotalMilliseconds > Core.MySQL_SyncInterval)
         {
             if (Core.MySQL_LogLevel > 2u)
             {
                 Helper.LogSQL("Thread \"ProcessUsers\": Synchronizing server data from MySQL database", false);
             }
             SystemTimestamp restart = SystemTimestamp.Restart;
             Events.bool_3 = true;
             Core.SQL_UpdateServer();
             if (Core.MySQL_Synchronize)
             {
                 Users.SQL_SynchronizeUsers();
             }
             if (Core.MySQL_Synchronize)
             {
                 Clans.SQL_SynchronizeClans();
             }
             Events.dateTime_0 = DateTime.Now;
             Events.bool_3     = false;
             restart.Stop();
             if (Core.MySQL_LogLevel > 2u)
             {
                 Helper.LogSQL("Thread \"ProcessUsers\": Synchronized, is took " + restart.ElapsedSeconds.ToString("0.0000") + " second(s).", false);
             }
         }
     }
 }
        private bool ProcessoDeSalvamento()
        {
            if (ServerIsSaving)
            {
                Logger.Log("[Fougerite WorldSave] Server's thread is still saving. We are ignoring the save request.");
                return(false);
            }

            ServerIsSaving = true;
            path           = ServerSaveManager.autoSavePath;

            AvatarSaveProc.SaveAll();
            DataStore.GetInstance().Save();

            restart = SystemTimestamp.Restart;
            if (path == string.Empty)
            {
                path = "savedgame.sav";
            }

            if (!path.EndsWith(".sav"))
            {
                path = path + ".sav";
            }

            if (ServerSaveManager._loading)
            {
                Logger.LogError("[Fougerite WorldSave] Currently loading, aborting save to " + path);
                return(false);
            }
            else
            {
                Debug.Log("Saving to '" + path + "'");
                if (!ServerSaveManager._loadedOnce)
                {
                    if (File.Exists(path))
                    {
                        string[] textArray1 = new string[]
                        {
                            path, ".", ServerSaveManager.DateTimeFileString(File.GetLastWriteTime(path)), ".",
                            ServerSaveManager.DateTimeFileString(DateTime.Now), ".bak"
                        };
                        string destFileName = string.Concat(textArray1);
                        File.Copy(path, destFileName);
                        Logger.LogError(
                            "A save file exists at target path, but it was never loaded!\n\tbacked up:" +
                            Path.GetFullPath(destFileName));
                    }

                    ServerSaveManager._loadedOnce = true;
                }

                using (Recycler <WorldSave, WorldSave.Builder> recycler = WorldSave.Recycler())
                {
                    if (recycler != null)
                    {
                        builder    = recycler.OpenBuilder();
                        timestamp2 = SystemTimestamp.Restart;
                        s          = ServerSaveManager.Get(false);
                    }
                    else
                    {
                        Logger.LogError("SOMETHING IS F****D, RECYCLER IS NULL.");
                    }
                }

                return(true);
            }
        }
        // funcoes normais
        private void SaveServer(object sender, DoWorkEventArgs e)
        {
            Logger.Log("SaveServer");
            try
            {
                Logger.Log("SaveScene...");
                SaveScene(ref builder);
                Logger.Log("SaveInstances...");
                SaveInstances(ref builder);
                Logger.Log("Next saves...");

                timestamp2.Stop();
                timestamp3 = SystemTimestamp.Restart;
                fsave      = builder.Build();
                timestamp3.Stop();
                int num = fsave.SceneObjectCount + fsave.InstanceObjectCount;

                Logger.Log("Salvando arquivo..." + path + " e seus backup.");

                SystemTimestamp timestamp5 = timestamp4 = SystemTimestamp.Restart;
                using (FileStream stream2 = File.Open(path + ".new", FileMode.Create, FileAccess.Write))
                {
                    fsave.WriteTo(stream2);
                    stream2.Flush();
                }

                timestamp4.Stop();
                if (File.Exists(path + ".old." + (SaveCopies + 1)))
                {
                    File.Delete(path + ".old." + (SaveCopies + 1));
                }

                for (int i = SaveCopies; i >= 0; i--)
                {
                    if (File.Exists(path + ".old." + i))
                    {
                        File.Move(path + ".old." + i, path + ".old." + (i + 1));
                    }
                }

                if (File.Exists(path))
                {
                    File.Move(path, path + ".old.0");
                }

                if (File.Exists(path + ".new"))
                {
                    File.Move(path + ".new", path);
                }
                timestamp5.Stop();
                restart.Stop();

                if (Hooks.IsShuttingDown)
                {
                    ServerIsSaving = false;
                    Logger.Log(string.Concat(new object[] { " Saved ", num, " Object(s). Took ", restart.ElapsedSeconds, " seconds." }));
                    //ProjectX.ProjectX.BroadCast(ProjectX.ProjectX.configServer.NameServer, "O servidor salvou [color green]" + num + "[/color] Objetos do mapa");
                    return;
                }

                Loom.QueueOnMainThread(() =>
                {
                    if (save.profile)
                    {
                        object[] args = new object[]
                        {
                            num, timestamp2.ElapsedSeconds,
                            timestamp2.ElapsedSeconds / restart.ElapsedSeconds, timestamp3.ElapsedSeconds,
                            timestamp3.ElapsedSeconds / restart.ElapsedSeconds, timestamp4.ElapsedSeconds,
                            timestamp4.ElapsedSeconds / restart.ElapsedSeconds, timestamp5.ElapsedSeconds,
                            timestamp5.ElapsedSeconds / restart.ElapsedSeconds, restart.ElapsedSeconds,
                            restart.ElapsedSeconds / restart.ElapsedSeconds
                        };
                        Logger.Log(string.Format(" Saved {0} Object(s) [times below are in elapsed seconds]\r\n  Logic:\t{1,-16:0.000000}\t{2,7:0.00%}\r\n  Build:\t{3,-16:0.000000}\t{4,7:0.00%}\r\n  Stream:\t{5,-16:0.000000}\t{6,7:0.00%}\r\n  All IO:\t{7,-16:0.000000}\t{8,7:0.00%}\r\n  Total:\t{9,-16:0.000000}\t{10,7:0.00%}", args));
                    }
                    else
                    {
                        Logger.Log(string.Concat(new object[] { " Saved ", num, " Object(s). Took ", restart.ElapsedSeconds, " seconds." }));
                        //ProjectX.ProjectX.BroadCast(ProjectX.ProjectX.configServer.NameServer, "O servidor salvou [color green]" + num + "[/color] Objetos do mapa");
                    }

                    Hooks.OnServerSaveEvent(num, restart.ElapsedSeconds);
                    ServerIsSaving = false;
                    LastSaveTime   = DateTime.Now;

                    // Process the unprocessed hashset values here without causing HashSet modified error.
                    List <ServerSave> RemovableKeys = new List <ServerSave>();

                    foreach (ServerSave x in UnProcessedSaves.Keys)
                    {
                        try
                        {
                            if (UnProcessedSaves.ContainsKey(x))
                            {
                                byte value = UnProcessedSaves[x];
                                if (value == 1)
                                {
                                    if (ServerSaveManager.Instances.registers.Add(x))
                                    {
                                        ServerSaveManager.Instances.ordered.Add(x);
                                    }

                                    ServerSaveManager.Instances.ordered.Add(x);
                                }
                                else
                                {
                                    if (ServerSaveManager.Instances.registers.Remove(x))
                                    {
                                        ServerSaveManager.Instances.ordered.Remove(x);
                                    }
                                }

                                RemovableKeys.Add(x);
                            }
                        }
                        catch (KeyNotFoundException ex)
                        {
                            Logger.LogError("[RegisterHook KeyNotFoundException] " + ex);
                        }
                        catch (Exception ex)
                        {
                            Logger.LogError("[RegisterHook Error] " + ex);
                        }
                    }

                    foreach (var x in RemovableKeys)
                    {
                        UnProcessedSaves.Remove(x);
                    }
                });
            }
            catch (Exception ex)
            {
                Logger.LogError("[ServerSaveHandler Error 0x2] " + ex);
                ServerIsSaving     = false;
                LastSaveTime       = DateTime.Now;
                NextServerSaveTime = LastSaveTime.AddMinutes(ServerSaveTime);
                if (StopServerOnSaveFail)
                {
                    Logger.LogWarning("[Fougerite WorldSave] We have caught an error. Killing server as requested.");
                    Process.GetCurrentProcess().Kill();
                }
            }
            finally
            {
                if (e != null && sender != null)
                {
                    Invoke(nameof(SalvarMapaComBackgroundWorker), ServerSaveTime * 60);
                }
            }
        }
Esempio n. 11
0
        private void StartBackGroundWorkerManualBackgroundSave()
        {
            if (ServerIsSaving)
            {
                Logger.Log(
                    "[Fougerite WorldSave] Server's thread is still saving. We are ignoring the save request.");
                return;
            }
            try
            {
                ServerIsSaving = true;
                path           = ServerSaveManager.autoSavePath;

                AvatarSaveProc.SaveAll();

                DataStore.GetInstance().Save();
                restart = SystemTimestamp.Restart;
                if (path == string.Empty)
                {
                    path = "savedgame.sav";
                }

                if (!path.EndsWith(".sav"))
                {
                    path = path + ".sav";
                }

                if (ServerSaveManager._loading)
                {
                    Logger.LogError("[Fougerite WorldSave] Currently loading, aborting save to " + path);
                }
                else
                {
                    Debug.Log("Saving to '" + path + "'");
                    if (!ServerSaveManager._loadedOnce)
                    {
                        if (File.Exists(path))
                        {
                            string[] textArray1 = new string[]
                            {
                                path, ".", ServerSaveManager.DateTimeFileString(File.GetLastWriteTime(path)), ".",
                                ServerSaveManager.DateTimeFileString(DateTime.Now), ".bak"
                            };
                            string destFileName = string.Concat(textArray1);
                            File.Copy(path, destFileName);
                            Logger.LogError(
                                "A save file exists at target path, but it was never loaded!\n\tbacked up:" +
                                Path.GetFullPath(destFileName));
                        }

                        ServerSaveManager._loadedOnce = true;
                    }

                    using (Recycler <WorldSave, WorldSave.Builder> recycler = WorldSave.Recycler())
                    {
                        if (recycler != null)
                        {
                            builder    = recycler.OpenBuilder();
                            timestamp2 = SystemTimestamp.Restart;
                            s          = ServerSaveManager.Get(false);
                        }
                        else
                        {
                            Logger.LogError("SOMETHING IS F****D, RECYCLER IS NULL.");
                        }
                    }


                    BackgroundWorker BGW = new BackgroundWorker();
                    BGW.DoWork += new DoWorkEventHandler(SaveServerManualWithoutInvoke);
                    BGW.RunWorkerAsync();
                }
            }
            catch (Exception ex)
            {
                Logger.LogError("[ServerSaveHandler Error1] " + ex);
            }
        }
Esempio n. 12
0
 protected void Update()
 {
     if (base.dead)
     {
         return;
     }
     try
     {
         this.UpdateInput();
     }
     finally
     {
         if ((!this.onceClock || this.clock.ElapsedSeconds > NetCull.sendInterval) && !base.dead)
         {
             this.onceClock = true;
             this.SendToServer();
             this.clock = SystemTimestamp.Restart;
         }
     }
 }
Esempio n. 13
0
 protected void OnEnable()
 {
     this.SetLocalOnlyComponentsEnabled(true);
     LockCursorManager.IsLocked(true);
     this.onceClock = false;
     this.clock = SystemTimestamp.Restart;
 }
Esempio n. 14
0
 public static void DoProcessUsers()
 {
     if (!bool_1)
     {
         bool_1 = true;
         foreach (UserData data in Users.All)
         {
             Character character;
             NetUser   player = NetUser.FindByUserID(data.SteamID);
             if ((player != null) && !player.did_join)
             {
                 player = null;
             }
             System.Collections.Generic.List <Countdown> list = new System.Collections.Generic.List <Countdown>();
             foreach (Countdown countdown in Users.CountdownList(data.SteamID))
             {
                 if (countdown.Expires)
                 {
                     if (countdown.Expired)
                     {
                         list.Add(countdown);
                     }
                     else if ((countdown.Command.Equals("pvp", StringComparison.OrdinalIgnoreCase) && data.HasFlag(UserFlags.nopvp)) && (Convert.ToInt32(countdown.TimeLeft) < Core.CommandNoPVPCountdown))
                     {
                         data.SetFlag(UserFlags.nopvp, false);
                         if (player != null)
                         {
                             Broadcast.Notice(player, "☢", Config.GetMessage("Command.PvP.Enabled", player, null), 5f);
                         }
                         Broadcast.NoticeAll("☢", Config.GetMessage("Command.PvP.NoticeEnabled", null, data.Username), player, 5f);
                     }
                 }
             }
             foreach (Countdown countdown2 in list)
             {
                 Users.CountdownRemove(data.SteamID, countdown2);
             }
             if ((data.PremiumDate.Millisecond != 0) && (data.PremiumDate < DateTime.Now))
             {
                 Users.SetFlags(data.SteamID, UserFlags.premium, false);
                 Users.SetRank(data.SteamID, Users.DefaultRank);
                 DateTime date = new DateTime();
                 Users.SetPremiumDate(data.SteamID, date);
                 Broadcast.Notice(player, "☢", Config.GetMessage("Player.Premium.Expired", null, null), 5f);
             }
             if (((Core.OwnershipDestroyAutoDisable > 0) && Core.DestoryOwnership.ContainsKey(data.SteamID)) && (Core.DestoryOwnership[data.SteamID] < DateTime.Now))
             {
                 Core.DestoryOwnership.Remove(data.SteamID);
                 if (player != null)
                 {
                     Broadcast.Notice(player, "☢", Config.GetMessage("Command.Destroy.Disabled", null, null), 5f);
                 }
             }
             if (((player != null) && player.did_join) && (player.admin && Character.FindByUser(player.userID, out character)))
             {
                 Metabolism component = character.GetComponent <Metabolism>();
                 if (component.GetCalorieLevel() < 3000f)
                 {
                     component.AddCalories(3000f - component.GetCalorieLevel());
                 }
                 if (component.GetRadLevel() > 0f)
                 {
                     component.AddAntiRad(component.GetRadLevel());
                 }
             }
         }
         bool_1 = false;
         if ((Core.DatabaseType.Equals("MYSQL") && !bool_3) && (DateTime.Now.Subtract(dateTime_0).TotalMilliseconds > Core.MySQL_SyncInterval))
         {
             if (Core.MySQL_LogLevel > 2)
             {
                 Helper.LogSQL("Thread \"ProcessUsers\": Synchronizing server data from MySQL database", false);
             }
             SystemTimestamp restart = SystemTimestamp.Restart;
             bool_3 = true;
             Core.SQL_UpdateServer();
             if (Core.MySQL_Synchronize)
             {
                 Users.SQL_SynchronizeUsers();
             }
             if (Core.MySQL_Synchronize)
             {
                 Clans.SQL_SynchronizeClans();
             }
             dateTime_0 = DateTime.Now;
             bool_3     = false;
             restart.Stop();
             if (Core.MySQL_LogLevel > 2)
             {
                 Helper.LogSQL("Thread \"ProcessUsers\": Synchronized, is took " + restart.ElapsedSeconds.ToString("0.0000") + " second(s).", false);
             }
         }
     }
 }