protected override void _Start() { SteamServer.OnValidateAuthTicketResponse += SteamServer_OnValidateAuthTicketResponse; var init = new SteamServerInit("fragsurf", "Fragsurf"); init.GamePort = (ushort)GameServer.Instance.Socket.GameplayPort; init.QueryPort = (ushort)SteamQueryPort; init.SteamPort = (ushort)SteamPort; init.VersionString = Structure.Version; try { SteamServer.Init(Structure.AppId, init); SteamServer.ServerName = GameServer.Instance.Socket.ServerName ?? DefaultServerName; SteamServer.DedicatedServer = true; SteamServer.Passworded = !string.IsNullOrEmpty(GameServer.Instance.Socket.ServerPassword); SteamServer.MaxPlayers = GameServer.Instance.Socket.MaxPlayers; SteamServer.AutomaticHeartbeats = true; SteamServer.LogOnAnonymous(); DevConsole.WriteLine($"Steamworks Server initialized\n - Name: {SteamServer.ServerName}\n - Password: {GameServer.Instance.Socket.ServerPassword}\n - Version: {init.VersionString}\n - Game Port: {init.GamePort} (This must be open to allow players to connect)\n - Query Port: {init.QueryPort} (This must be open to show on master server list)\n - Steam Port: {init.SteamPort} (This must be open to show on master server list)"); GameObject.FindObjectOfType <ServerConsole>()?.SetTitle(GameServer.Instance.Socket.ServerName); } catch (Exception e) { Debug.LogError(e.ToString()); } }
public async Task Server(int delay = 100) { Print("Initializing Server"); // // Init Server // var serverInit = new SteamServerInit("rust", "Rusty Mode") { GamePort = 28015, Secure = true, QueryPort = 28016 }; Steamworks.SteamServer.Init(252490, serverInit); SteamServer.LogOnAnonymous(); Print("Server Initliazed"); await Task.Delay(1000); await TestServerAuth(delay); await Task.Delay(1000); Print("Closing Server"); Steamworks.SteamServer.Shutdown(); }
public async Task SetupAsync() { ConfigureServices(); Logger logger = ServiceProvider.GetService <ILoggerProvider>() .GetLogger("Server"); logger.LogInformation("Starting server"); ServerConfig config = ServiceProvider.GetService <IConfigProvider>().Config; SteamServerInit init = new SteamServerInit { GamePort = config.Port, Secure = true, QueryPort = (ushort)(config.Port + 1), SteamPort = (ushort)(config.Port + 2), VersionString = "0.1", DedicatedServer = true, IpAddress = IPAddress.Parse(config.IpAddress), ModDir = "pf", GameDescription = "Pony Forest" }; try { SteamServer.Init(1026040, init); SteamServer.ServerName = config.Name; SteamServer.AutomaticHeartbeats = true; SteamServer.DedicatedServer = true; SteamServer.Passworded = false; SteamServer.MaxPlayers = config.MaxPlayers; SteamServer.LogOnAnonymous(); NetAddress address = NetAddress.From(config.IpAddress, config.Port); _serverCore = SteamNetworkingSockets.CreateNormalSocket <ServerCore>(address); } catch (Exception e) { logger.LogFailure($"Can't start server: {Environment.NewLine + e}"); } try { IMessageRouter messageRouter = ServiceProvider.GetService <IMessageRouter>(); logger.LogInformation("Server started"); _serverCore.OnMessageReceived = messageRouter.Route; IMessageListener messageListener = ServiceProvider.GetService <IMessageListener>(); await messageListener.StartListening(_serverCore); } catch (Exception e) { logger.LogFailure($"Error while running server: {Environment.NewLine + e}"); } }
private void Initialize(ushort gamePort, ushort steamPort, ushort queryPort, string serverName, int maxPlayers) { SteamServerInit init = new SteamServerInit("Conquest", "Conquest") { GamePort = gamePort, SteamPort = steamPort, QueryPort = queryPort, VersionString = "1.0", Secure = true }; try { SteamServer.Init(923440, init); } catch (Exception e) { logger.LogWarning(e.Message); } SteamServer.ServerName = serverName; SteamServer.MaxPlayers = maxPlayers; SteamServer.Passworded = false; SteamServer.DedicatedServer = true; SteamServer.LogOnAnonymous(); if (logger.LogEnabled()) { logger.Log("Logged on as Anonymous"); } }
void Start() { DontDestroyOnLoad(this); SteamServerInit serverInit = new SteamServerInit("gmod", "Garry Mode") { GamePort = 28015, Secure = true, QueryPort = 28016, DedicatedServer = false }; try { SteamServer.Init(480, serverInit); } catch (System.Exception e) { Debug.Log(e); } SteamServer.OnSteamServersConnected += () => { Debug.Log("Connected"); }; }
private void StartSteamServer() { if (SteamServer.IsValid) { return; } IPAddress pAddress = null; if (!string.IsNullOrEmpty(ConVar.Server.ip)) { pAddress = IPAddress.Parse(ConVar.Server.ip); } SteamServerInit steamServerInit = new SteamServerInit("rust", "Rust") { IpAddress = pAddress, GamePort = (ushort)Network.Net.sv.port, Secure = ConVar.Server.secure, VersionString = 2177.ToString() }; if (!this.useQueryPort) { steamServerInit = steamServerInit.WithQueryShareGamePort(); } else { steamServerInit.QueryPort = (ushort)ConVar.Server.queryport; } SteamServer.OnCallbackException = (Exception e) => { UnityEngine.Debug.LogError(e.Message); UnityEngine.Debug.LogError(e.StackTrace); }; try { SteamServer.Init(Rust.Defines.appID, steamServerInit); } catch (Exception exception1) { Exception exception = exception1; UnityEngine.Debug.LogWarning(string.Concat("Couldn't initialize Steam Server (", exception.Message, ")")); UnityEngine.Application.Quit(); return; } SteamServer.OnValidateAuthTicketResponse += new Action <SteamId, SteamId, AuthResponse>(this.OnValidateAuthTicketResponse); SteamServer.OnSteamServerConnectFailure += new Action <Result, bool>(this.OnSteamConnectionFailure); SteamServer.OnSteamServersDisconnected += new Action <Result>(this.OnSteamServersDisconnected); SteamServer.OnSteamServersConnected += new Action(this.OnSteamConnected); Steamworks.SteamInventory.OnDefinitionsUpdated += new Action(this.OnInventoryDefinitionsUpdated); SteamServer.DedicatedServer = true; SteamServer.LogOnAnonymous(); base.InvokeRepeating("UpdateServerInformation", 2f, 30f); base.InvokeRepeating("UpdateItemDefinitions", 10f, 3600f); DebugEx.Log("SteamServer Initialized", StackTraceLogType.None); }
public void CreateSteamServer() { SteamServerInit init = new SteamServerInit { IpAddress = System.Net.IPAddress.Any, Secure = true, DedicatedServer = true, GameDescription = serverDescription, GamePort = gamePort, QueryPort = queryPort, SteamPort = 27015, ModDir = "DedicatedTest", VersionString = "1.0.0.0" }; SteamServer.Init(1551700, init, true); }
public void StartServer() { if (!initialized) { Debug.LogError("Error run Initialize() before running StartServer()."); return; } SteamServerInit serverInitData = new SteamServerInit(NetServer.serverInstance.modDir, NetServer.serverInstance.gameDesc) { }; serverInitData.DedicatedServer = false; serverInitData.GamePort = (ushort)NetServer.serverInstance.hostPort; SteamServer.Init(NetServer.serverInstance.steamAppID, serverInitData); SteamServer.ServerName = SteamClient.Name + "'s Server."; SteamServer.MapName = NetServer.serverInstance.mapName; SteamServer.MaxPlayers = NetServer.serverInstance.maxConnections; SteamServer.AutomaticHeartbeats = true; SteamServer.LogOnAnonymous(); doCallbacks = true; SteamServer.OnValidateAuthTicketResponse += (steamid, ownerid, response) => { if (response == AuthResponse.OK) { Debug.Log(steamid + " ticket is still valid"); } else { Debug.Log(steamid + " ticket is no longer valid"); //Add kick user stuff. } }; serverRunning = true; //steamSocket = new SteamSocketManager(); //steamworksServerManager = SteamNetworkingSockets.CreateNormalSocket(Steamworks.Data.NetAddress.AnyIp((ushort)NetServer.serverInstance.hostPort), steamSocket); }
public Server( SteamSockets transport, int maxConnections, uint steamAppID, SteamServerInit init, SteamSockets.SocketMode socketMode, string serverName ) { if (transport.debug) { Debug.Log($"SteamSockets.Server: Starting"); } networkPort = init.GamePort; SteamServer.Init(steamAppID, init, false); SteamServer.ServerName = serverName; if (String.IsNullOrEmpty(transport.gsToken)) { Debug.Log($"No gsToken provided, logging on anonymously"); SteamServer.LogOnAnonymous(); } else { Debug.Log($"Logging on with gstoken"); // Todo: Add SteamServer.LogOn(gsToken); when Facepunch.Steamworks supports it } if (transport.debug) { Debug.Log($"Creating socket manager ({socketMode})"); } switch (socketMode) { case SteamSockets.SocketMode.P2P: socketManager = SteamNetworkingSockets.CreateRelaySocket <FPSocketManager>(); break; case SteamSockets.SocketMode.UDP: socketManager = SteamNetworkingSockets.CreateNormalSocket <FPSocketManager>(NetAddress.AnyIp(networkPort)); break; } socketManager.transport = transport; }
public void Initialize(ushort gamePort, ushort steamPort, ushort queryPort, string serverName, int maxPlayers) { try { System.IO.File.WriteAllText("steam_appid.txt", "923440"); } catch (System.Exception e) { Debug.LogWarning("Couldn't write steam_appid.txt: " + e.Message); } var init = new SteamServerInit("Revision", "Revision") { GamePort = gamePort, SteamPort = steamPort, QueryPort = queryPort, VersionString = "1.0", Secure = true }; try { SteamServer.Init(923440, init); } catch (System.Exception e) { Debug.LogWarning(e.Message); } SteamServer.ServerName = serverName; SteamServer.MaxPlayers = maxPlayers; SteamServer.Passworded = false; SteamServer.DedicatedServer = true; SteamServer.OnValidateAuthTicketResponse += OnValidateAuthTicketResponse; SteamServer.LogOnAnonymous(); }
private async void StartSteamServer(CancellationTokenSource source) { var token = source.Token; void InitializeSteamServer() { const int GAME_PORT = 30001; const int APP_ID = 480; const int QUERY_PORT = GAME_PORT + 1; Console.WriteLine($"########### STARTING STEAM SREVER ##################"); SteamServerInit serverInit = new SteamServerInit("TestInitSteamServer", "TestInitSteamServer TEST") { GamePort = GAME_PORT, Secure = true, QueryPort = QUERY_PORT, VersionString = "0.0.0.1" }; try { //SteamServer.DedicatedServer = true; SteamServer.OnCallbackException += OnCallbackException; SteamServer.OnSteamServerConnectFailure += OnSteamServerConnectFailure; SteamServer.OnSteamServersConnected += OnSteamServersConnected; SteamServer.OnSteamServersDisconnected += OnSteamServersDisconnected; SteamServer.OnValidateAuthTicketResponse += OnValidateAuthTicketResponse; SteamServer.Init(APP_ID, serverInit); SteamServer.DedicatedServer = true; SteamServer.LogOnAnonymous(); SocketInterface socket = SteamNetworkingSockets.CreateNormalSocket <SocketInterface>(NetAddress.AnyIp(GAME_PORT)); } catch (System.Exception e) { Console.WriteLine($"#### SteamServer e:{e.Message}\n:{e.StackTrace}"); // Couldn't init for some reason (dll errors, blocked ports) SteamServer.Shutdown(); } Console.WriteLine($"#### SteamServer IsValid:{SteamServer.IsValid} IsLogedOn:{SteamServer.LoggedOn}"); } void UpdateSteamServerCallbacks() { const long UPDATE_INTERVAL_IN_MS = 1000; long lastTimeInMs = long.MinValue; long currentTimeInMs; try { while (true) { token.ThrowIfCancellationRequested(); if (lastTimeInMs + UPDATE_INTERVAL_IN_MS < (currentTimeInMs = DateTime.UtcNow.ToTotalMillisUTC())) { lastTimeInMs = currentTimeInMs; Console.WriteLine($"\tSteamServer Updating {lastTimeInMs}"); SteamServer.RunCallbacks(); } } } finally { SteamServer.Shutdown(); Console.WriteLine($"#### SteamServer Shutdown"); } } await Task.Run(() => InitializeSteamServer()); await Task.Factory.StartNew((x) => UpdateSteamServerCallbacks(), token, TaskCreationOptions.LongRunning); }