Пример #1
0
        public override void Close(string msg = null)
        {
            if (netServer == null)
            {
                return;
            }

            for (int i = pendingClients.Count - 1; i >= 0; i--)
            {
                RemovePendingClient(pendingClients[i], DisconnectReason.ServerShutdown, msg);
            }

            for (int i = connectedClients.Count - 1; i >= 0; i--)
            {
                Disconnect(connectedClients[i], msg ?? DisconnectReason.ServerShutdown.ToString());
            }

            netServer.Shutdown(msg ?? DisconnectReason.ServerShutdown.ToString());

            pendingClients.Clear();
            connectedClients.Clear();

            netServer = null;

            if (steamServer != null)
            {
                steamServer.Auth.OnAuthChange = null;
            }
            steamServer = null;

            OnShutdown?.Invoke();
        }
Пример #2
0
    private void StartSteamServer()
    {
        if (Global.get_SteamServer() != null)
        {
            return;
        }
        IPAddress ipAddress = (IPAddress)null;

        if (!string.IsNullOrEmpty(ConVar.Server.ip))
        {
            ipAddress = IPAddress.Parse(ConVar.Server.ip);
        }
        Config.ForUnity(Application.get_platform().ToString());
        ServerInit serverInit = new ServerInit("rust", "Rust");

        serverInit.IpAddress     = (__Null)ipAddress;
        serverInit.GamePort      = (__Null)(int)(ushort)((Network.Server)Network.Net.sv).port;
        serverInit.Secure        = (__Null)(ConVar.Server.secure ? 1 : 0);
        serverInit.VersionString = (__Null)2161.ToString();
        if (this.useQueryPort)
        {
            serverInit.QueryPort = (__Null)(int)(ushort)ConVar.Server.queryport;
        }
        else
        {
            serverInit.QueryShareGamePort();
        }
        Global.set_SteamServer(new Facepunch.Steamworks.Server(Defines.appID, serverInit));
        if (!((BaseSteamworks)Global.get_SteamServer()).get_IsValid())
        {
            Debug.LogWarning((object)("Couldn't initialize Steam Server (" + (object)ipAddress + ")"));
            ((BaseSteamworks)Global.get_SteamServer()).Dispose();
            Global.set_SteamServer((Facepunch.Steamworks.Server)null);
            Application.Quit();
        }
        else
        {
            if (CommandLine.HasSwitch("-debugsteamcallbacks"))
            {
                Facepunch.Steamworks.Server steamServer = Global.get_SteamServer();
                ((BaseSteamworks)steamServer).OnAnyCallback = (__Null)Delegate.Combine((Delegate)((BaseSteamworks)steamServer).OnAnyCallback, (Delegate) new Action <object>(ServerMgr.DebugPrintSteamCallback));
            }
            Global.get_SteamServer().get_Auth().OnAuthChange = (__Null) new Action <ulong, ulong, ServerAuth.Status>(this.OnValidateAuthTicketResponse);
            ((BaseSteamworks)Global.get_SteamServer()).get_Inventory().add_OnDefinitionsUpdated(new Action(this.OnInventoryDefinitionsUpdated));
            Global.get_SteamServer().LogOnAnonymous();
            ((MonoBehaviour)this).InvokeRepeating("UpdateServerInformation", 1f, 10f);
            DebugEx.Log((object)"Connected to Steam", (StackTraceLogType)0);
        }
    }
Пример #3
0
        public LidgrenServerPeer(int?ownKey, ServerSettings settings)
        {
            serverSettings = settings;

            netServer = null;

            connectedClients = new List <LidgrenConnection>();
            pendingClients   = new List <PendingClient>();

            incomingLidgrenMessages = new List <NetIncomingMessage>();

            steamServer = null;

            ownerKey = ownKey;
        }
Пример #4
0
 public abstract void InitializeSteamServerCallbacks(Facepunch.Steamworks.Server steamSrvr);
Пример #5
0
        public override void InitializeSteamServerCallbacks(Server steamSrvr)
        {
            steamServer = steamSrvr;

            steamServer.Auth.OnAuthChange = OnAuthChange;
        }
Пример #6
0
 private void UpdateServerInformation()
 {
     if (Global.get_SteamServer() == null)
     {
         return;
     }
     using (TimeWarning.New(nameof(UpdateServerInformation), 0.1f))
     {
         Global.get_SteamServer().set_ServerName(ConVar.Server.hostname);
         Global.get_SteamServer().set_MaxPlayers(ConVar.Server.maxplayers);
         Global.get_SteamServer().set_Passworded(false);
         Global.get_SteamServer().set_MapName(World.Name);
         string str1 = "stok";
         if (this.Restarting)
         {
             str1 = "strst";
         }
         string str2 = string.Format("born{0}", (object)Epoch.FromDateTime(SaveRestore.SaveCreatedTime));
         string str3 = string.Format("mp{0},cp{1},qp{5},v{2}{3},h{4},{6},{7}", (object)ConVar.Server.maxplayers, (object)BasePlayer.activePlayerList.Count, (object)2161, ConVar.Server.pve ? (object)",pve" : (object)string.Empty, (object)this.AssemblyHash, (object)((ServerMgr)SingletonComponent <ServerMgr> .Instance).connectionQueue.Queued, (object)str1, (object)str2) + ",oxide";
         if (Interface.get_Oxide().get_Config().get_Options().Modded != null)
         {
             str3 += ",modded";
         }
         Global.get_SteamServer().set_GameTags(str3);
         if (ConVar.Server.description != null && ConVar.Server.description.Length > 100)
         {
             string[] array = StringEx.SplitToChunks(ConVar.Server.description, 100).ToArray <string>();
             for (int index = 0; index < 16; ++index)
             {
                 if (index < array.Length)
                 {
                     Global.get_SteamServer().SetKey(string.Format("description_{0:00}", (object)index), array[index]);
                 }
                 else
                 {
                     Global.get_SteamServer().SetKey(string.Format("description_{0:00}", (object)index), string.Empty);
                 }
             }
         }
         else
         {
             Global.get_SteamServer().SetKey("description_0", ConVar.Server.description);
             for (int index = 1; index < 16; ++index)
             {
                 Global.get_SteamServer().SetKey(string.Format("description_{0:00}", (object)index), string.Empty);
             }
         }
         Global.get_SteamServer().SetKey("hash", this.AssemblyHash);
         Facepunch.Steamworks.Server steamServer1 = Global.get_SteamServer();
         uint   num  = World.Seed;
         string str4 = num.ToString();
         steamServer1.SetKey("world.seed", str4);
         Facepunch.Steamworks.Server steamServer2 = Global.get_SteamServer();
         num = World.Size;
         string str5 = num.ToString();
         steamServer2.SetKey("world.size", str5);
         Global.get_SteamServer().SetKey("pve", ConVar.Server.pve.ToString());
         Global.get_SteamServer().SetKey("headerimage", ConVar.Server.headerimage);
         Global.get_SteamServer().SetKey("url", ConVar.Server.url);
         Global.get_SteamServer().SetKey("uptime", ((int)Time.get_realtimeSinceStartup()).ToString());
         Global.get_SteamServer().SetKey("gc_mb", Performance.report.memoryAllocations.ToString());
         Global.get_SteamServer().SetKey("gc_cl", Performance.report.memoryCollections.ToString());
         Global.get_SteamServer().SetKey("fps", Performance.report.frameRate.ToString());
         Global.get_SteamServer().SetKey("fps_avg", Performance.report.frameRateAverage.ToString("0.00"));
         Global.get_SteamServer().SetKey("ent_cnt", BaseNetworkable.serverEntities.Count.ToString());
         Global.get_SteamServer().SetKey("build", BuildInfo.get_Current().get_Scm().get_ChangeId());
     }
 }