예제 #1
0
    public static void InitializeEntitySupports()
    {
        if (!ConVar.Server.stability)
        {
            return;
        }
        StabilityEntity[] array = BaseNetworkable.serverEntities.Where <BaseNetworkable>((Func <BaseNetworkable, bool>)(x => x is StabilityEntity)).Select <BaseNetworkable, StabilityEntity>((Func <BaseNetworkable, StabilityEntity>)(x => x as StabilityEntity)).ToArray <StabilityEntity>();
        if (array.Length == 0)
        {
            return;
        }
        DebugEx.Log((object)("Initializing " + (object)array.Length + " stability supports"), (StackTraceLogType)0);
        Stopwatch stopwatch = Stopwatch.StartNew();

        for (int index = 0; index < array.Length; ++index)
        {
            RCon.Update();
            array[index].InitializeSupports();
            if (stopwatch.Elapsed.TotalMilliseconds > 2000.0)
            {
                stopwatch.Reset();
                stopwatch.Start();
                DebugEx.Log((object)("\t" + (object)(index + 1) + " / " + (object)array.Length), (StackTraceLogType)0);
            }
        }
        DebugEx.Log((object)"\tdone.", (StackTraceLogType)0);
    }
예제 #2
0
 private void DoTick()
 {
     if (Global.get_SteamServer() != null)
     {
         Interface.CallHook("OnTick");
         ((BaseSteamworks)Global.get_SteamServer()).Update();
     }
     RCon.Update();
     for (int index = 0; index < ((List <Network.Connection>)((Network.Server)Network.Net.sv).connections).Count; ++index)
     {
         Network.Connection connection = ((List <Network.Connection>)((Network.Server)Network.Net.sv).connections)[index];
         if (!connection.get_isAuthenticated() && (double)connection.GetSecondsConnected() >= (double)ConVar.Server.authtimeout)
         {
             ((Network.Server)Network.Net.sv).Kick(connection, "Authentication Timed Out");
         }
     }
 }
예제 #3
0
 private void DoTick()
 {
     if (SteamServer.IsValid)
     {
         Interface.CallHook("OnTick");
         SteamServer.RunCallbacks();
     }
     RCon.Update();
     for (int i = 0; i < Network.Net.sv.connections.Count; i++)
     {
         Network.Connection item = Network.Net.sv.connections[i];
         if (!item.isAuthenticated && item.GetSecondsConnected() >= (float)ConVar.Server.authtimeout)
         {
             Network.Net.sv.Kick(item, "Authentication Timed Out");
         }
     }
 }
예제 #4
0
    public static void InitializeEntityConditionals()
    {
        BuildingBlock[] array = BaseNetworkable.serverEntities.Where <BaseNetworkable>((Func <BaseNetworkable, bool>)(x => x is BuildingBlock)).Select <BaseNetworkable, BuildingBlock>((Func <BaseNetworkable, BuildingBlock>)(x => x as BuildingBlock)).ToArray <BuildingBlock>();
        if (array.Length == 0)
        {
            return;
        }
        DebugEx.Log((object)("Initializing " + (object)array.Length + " conditional models"), (StackTraceLogType)0);
        Stopwatch stopwatch = Stopwatch.StartNew();

        for (int index = 0; index < array.Length; ++index)
        {
            RCon.Update();
            array[index].UpdateSkin(true);
            if (stopwatch.Elapsed.TotalMilliseconds > 2000.0)
            {
                stopwatch.Reset();
                stopwatch.Start();
                DebugEx.Log((object)("\t" + (object)(index + 1) + " / " + (object)array.Length), (StackTraceLogType)0);
            }
        }
        DebugEx.Log((object)"\tdone.", (StackTraceLogType)0);
    }
예제 #5
0
 public static bool Load(string strFilename = "", bool allowOutOfDateSaves = false)
 {
     SaveRestore.SaveCreatedTime = DateTime.UtcNow;
     try
     {
         if (strFilename == "")
         {
             strFilename = World.SaveFolderName + "/" + World.SaveFileName;
         }
         if (!File.Exists(strFilename))
         {
             if (File.Exists("TestSaves/" + strFilename))
             {
                 strFilename = "TestSaves/" + strFilename;
             }
             else
             {
                 Debug.LogWarning((object)("Couldn't load " + strFilename + " - file doesn't exist"));
                 Interface.CallHook("OnNewSave", (object)strFilename);
                 return(false);
             }
         }
         Dictionary <BaseEntity, Entity> dictionary = new Dictionary <BaseEntity, Entity>();
         using (FileStream fileStream = File.OpenRead(strFilename))
         {
             using (BinaryReader binaryReader = new BinaryReader((Stream)fileStream))
             {
                 SaveRestore.SaveCreatedTime = File.GetCreationTime(strFilename);
                 if (binaryReader.ReadSByte() != (sbyte)83 || binaryReader.ReadSByte() != (sbyte)65 || (binaryReader.ReadSByte() != (sbyte)86 || binaryReader.ReadSByte() != (sbyte)82))
                 {
                     Debug.LogWarning((object)"Invalid save (missing header)");
                     return(false);
                 }
                 if (binaryReader.PeekChar() == 68)
                 {
                     int num = (int)binaryReader.ReadChar();
                     SaveRestore.SaveCreatedTime = Epoch.ToDateTime((Decimal)binaryReader.ReadInt32());
                 }
                 if (binaryReader.ReadUInt32() != 177U)
                 {
                     if (allowOutOfDateSaves)
                     {
                         Debug.LogWarning((object)"This save is from an older (possibly incompatible) version!");
                     }
                     else
                     {
                         Debug.LogWarning((object)"This save is from an older version. It might not load properly.");
                     }
                 }
                 SaveRestore.ClearMapEntities();
                 Assert.IsTrue(BaseEntity.saveList.Count == 0, "BaseEntity.saveList isn't empty!");
                 ((Network.Server)Net.sv).Reset();
                 Application.isLoadingSave = (__Null)1;
                 HashSet <uint> uintSet = new HashSet <uint>();
                 while (fileStream.Position < fileStream.Length)
                 {
                     RCon.Update();
                     uint   num     = binaryReader.ReadUInt32();
                     Entity entData = Entity.DeserializeLength((Stream)fileStream, (int)num);
                     if (entData.basePlayer != null && ((IEnumerable <KeyValuePair <BaseEntity, Entity> >)dictionary).Any <KeyValuePair <BaseEntity, Entity> >((Func <KeyValuePair <BaseEntity, Entity>, bool>)(x =>
                     {
                         if (x.Value.basePlayer != null)
                         {
                             return(((BasePlayer)x.Value.basePlayer).userid == ((BasePlayer)entData.basePlayer).userid);
                         }
                         return(false);
                     })))
                     {
                         Debug.LogWarning((object)("Skipping entity " + (object)(uint)((BaseNetworkable)entData.baseNetworkable).uid + " - it's a player " + (object)(ulong)((BasePlayer)entData.basePlayer).userid + " who is in the save multiple times"));
                     }
                     else if (((BaseNetworkable)entData.baseNetworkable).uid > 0 && uintSet.Contains((uint)((BaseNetworkable)entData.baseNetworkable).uid))
                     {
                         Debug.LogWarning((object)("Skipping entity " + (object)(uint)((BaseNetworkable)entData.baseNetworkable).uid + " " + StringPool.Get((uint)((BaseNetworkable)entData.baseNetworkable).prefabID) + " - uid is used multiple times"));
                     }
                     else
                     {
                         if (((BaseNetworkable)entData.baseNetworkable).uid > 0)
                         {
                             uintSet.Add((uint)((BaseNetworkable)entData.baseNetworkable).uid);
                         }
                         BaseEntity entity = GameManager.server.CreateEntity(StringPool.Get((uint)((BaseNetworkable)entData.baseNetworkable).prefabID), (Vector3)((BaseEntity)entData.baseEntity).pos, Quaternion.Euler((Vector3)((BaseEntity)entData.baseEntity).rot), true);
                         if (Object.op_Implicit((Object)entity))
                         {
                             entity.InitLoad((uint)((BaseNetworkable)entData.baseNetworkable).uid);
                             dictionary.Add(entity, entData);
                         }
                     }
                 }
             }
         }
         DebugEx.Log((object)("Spawning " + (object)dictionary.Count + " entities"), (StackTraceLogType)0);
         object obj = Interface.CallHook("OnSaveLoad", (object)dictionary);
         if (obj is bool)
         {
             return((bool)obj);
         }
         BaseNetworkable.LoadInfo info = new BaseNetworkable.LoadInfo();
         info.fromDisk = true;
         Stopwatch stopwatch = Stopwatch.StartNew();
         int       num1      = 0;
         using (Dictionary <BaseEntity, Entity> .Enumerator enumerator = dictionary.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 KeyValuePair <BaseEntity, Entity> current = enumerator.Current;
                 BaseEntity key = current.Key;
                 if (!Object.op_Equality((Object)key, (Object)null))
                 {
                     RCon.Update();
                     info.msg = current.Value;
                     key.Spawn();
                     key.Load(info);
                     if (key.IsValid())
                     {
                         ++num1;
                         if (stopwatch.Elapsed.TotalMilliseconds > 2000.0)
                         {
                             stopwatch.Reset();
                             stopwatch.Start();
                             DebugEx.Log((object)("\t" + (object)num1 + " / " + (object)dictionary.Count), (StackTraceLogType)0);
                         }
                     }
                 }
             }
         }
         using (Dictionary <BaseEntity, Entity> .Enumerator enumerator = dictionary.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 BaseEntity key = enumerator.Current.Key;
                 if (!Object.op_Equality((Object)key, (Object)null))
                 {
                     RCon.Update();
                     if (key.IsValid())
                     {
                         key.PostServerLoad();
                     }
                 }
             }
         }
         DebugEx.Log((object)"\tdone.", (StackTraceLogType)0);
         if (Object.op_Implicit((Object)SingletonComponent <SpawnHandler> .Instance))
         {
             DebugEx.Log((object)"Enforcing SpawnPopulation Limits", (StackTraceLogType)0);
             ((SpawnHandler)SingletonComponent <SpawnHandler> .Instance).EnforceLimits(false);
             DebugEx.Log((object)"\tdone.", (StackTraceLogType)0);
         }
         Application.isLoadingSave = (__Null)0;
         return(true);
     }
     catch (Exception ex)
     {
         Debug.LogWarning((object)("Error loading save (" + strFilename + ")"));
         Debug.LogException(ex);
         return(false);
     }
 }