Facepunch / Facepunch.Steamworks

Another fucking c# Steamworks implementation
MIT License
2.92k stars 350 forks source link

Do i need a Socket Server to show it on master server? #403

Closed TiToMoskito closed 4 years ago

TiToMoskito commented 4 years ago

Is there something i made wrong? My Client doesnt show any servers on the master server. Server

void Awake()
{
    DontDestroyOnLoad(gameObject);
    Application.runInBackground = true;
    SceneManager.sceneLoaded += OnSceneLoaded;

    m_GameTools.InitializeServer();
    NetworkManager.InitializeNetwork();
    m_mapManager = new MapManager();
    m_mapManager.Initialize();

    Zapnet.Network.Host(28015, new ServerHandler(), m_serverSimulation);
    SceneManager.LoadScene("mode", LoadSceneMode.Single);

    GameDebug.Log("Dedicated Server initialized");

    SteamServerInit serverInit = new SteamServerInit("mods", "Race Project");
    serverInit.IpAddress = IPAddress.Parse("0.0.0.0");
    serverInit.QueryPort = 28016;
    serverInit.GamePort = 28015;
    serverInit.Secure = true;
    serverInit.VersionString = Application.version;

    try
    {
        SteamServer.Init(1284600, serverInit, true);
    }
    catch (Exception ex)
    {
        GameDebug.LogError("Couldn't initialize Steam Server (" + ex.Message + ")");
        Application.Quit();
    }

    SteamServer.OnSteamNetAuthenticationStatus += OnSteamNetAuthenticationStatus;
    SteamServer.OnSteamServersConnected += OnSteamServersConnected;
    SteamServer.OnSteamServersDisconnected += OnSteamServersDisconnected;
    SteamServer.OnSteamServerConnectFailure += OnSteamServerConnectFailure;
    SteamServer.OnValidateAuthTicketResponse += OnValidateAuthTicketResponse;
    SteamServer.DedicatedServer = true;
    SteamServer.LogOnAnonymous();

    GameDebug.Log("Steam Server Initialized");

    SteamNetworkingUtils.DebugLevel = NetDebugOutput.Warning | NetDebugOutput.Error | NetDebugOutput.Debug;
    SteamNetworkingUtils.OnDebugOutput += OnDebugOutput;

    //SteamNetworkingSockets.CreateNormalSocket(NetAddress.AnyIp(28015), this);
}

Client

void Start()
{     
    m_Internet = new Internet();
    m_Internet.OnChanges += OnServersUpdated;
    m_Internet.RunQueryAsync();
}

void OnServersUpdated()
{
    // No reponsive servers yet, bail
    if (m_Internet.Responsive.Count == 0)
        return;

    // Process each responsive server
    foreach (var s in m_Internet.Responsive)
    {
        ServerResponded(s);
    }

    // Clear the responsive server list so we don't
    // reprocess them on the next call.
    m_Internet.Responsive.Clear();
}

void ServerResponded(ServerInfo server)
{
    // Do whatever you want with the server information

    GameDebug.Log($"{server.Name} Responded!");
}
m4chado1 commented 4 years ago

Have you tried to use the normal steam server list?

Are you searching in Internet or LocalHost?

If you are searching at the Internet() try to change to Localhost().

TiToMoskito commented 4 years ago

Yes i can found the server via the normal steam server list. Thank you very much. I have a last stupid question, how do i connect to the server to be able to use the OnValidateAuthTicketResponse callback?

garrynewman commented 4 years ago

That depends what network solution you're using. You don't really connect via Steam. The client connects to the server, then it sends the auth ticket, then the server asks Steam to validate the auth ticket - then the OnValidateAuthTicketResponse is called by Steam on the server and you can either fully let the client in the server or reject them.