rlabrecque / Steamworks.NET

Steamworks wrapper for Unity / C#
http://steamworks.github.io
MIT License
2.81k stars 368 forks source link

RequestLobbyList never calls calllback in c# standalone project #489

Open Entretoize opened 2 years ago

Entretoize commented 2 years ago

I'm using Steamworks.net in a unity project with success, I can't create lobbies and retrieve a list. I need to create a simple c# app in visual studio notifying me of users playing my steam game so I decide to take about the same code:

using Steamworks;
using System.Collections;
using System.Collections.Generic;

if (!SteamAPI.Init())
{
    Console.WriteLine("Init failed !");
    return;
}

Console.WriteLine("Steam initialized ");

var m_LobbyMatchList = CallResult<LobbyMatchList_t>.Create(OnLobbyMatchList);

void OnLobbyMatchList(LobbyMatchList_t list, bool bIOFailure)
{
    uint numLobbies = list.m_nLobbiesMatching;

    if (numLobbies <= 0)
    {
        Console.WriteLine("No lobby");
    }
    else
    {
        for (var i = 0; i < numLobbies; i++)
        {
            var lobby = SteamMatchmaking.GetLobbyByIndex(i);
            var name = SteamMatchmaking.GetLobbyData(lobby, "name");
            var nolevel = SteamMatchmaking.GetLobbyData(lobby, "nolevel");
            var nplayers = SteamMatchmaking.GetNumLobbyMembers(lobby);
            var maxplayers = SteamMatchmaking.GetLobbyMemberLimit(lobby);

            if (name.Length == 0)
                continue;

            //var li=new Lobbyitem(name, lobby.m_SteamID, 0);
            Console.WriteLine("Lobby "+i + name + " niveau "+nolevel+" "+ nplayers+"/"+ maxplayers);
        }
    }
}

while(true)
{
    Thread.Sleep(5000);
    Console.WriteLine("Request lobby list...");
    SteamAPICall_t hSteamAPICall = SteamMatchmaking.RequestLobbyList();
    m_LobbyMatchList.Set(hSteamAPICall, OnLobbyMatchList);

}

Everything seams to run fine except that OnLobbyMatchList is never called. Can someone tells me what I am missing ? Nearly the same code works in unity in my game.

Thanks

zuev93 commented 1 year ago

I believe you're missing call of SteamAPI.RunCallbacks() that need to be done in order to make callbacks work