示例#1
0
        private void InitializeClient()
        {
            // client/manager creation
            Client  = new SteamClient();
            Manager = new CallbackManager(Client);

            _user      = Client.GetHandler <SteamUser>();
            _apps      = Client.GetHandler <SteamApps>();
            _userStats = Client.GetHandler <SteamUserStats>();

            Client.AddHandler(new SteamTicketAuth());
            Client.AddHandler(new SteamStatsHandler());

            // subscriptions
            Manager.Subscribe <SteamClient.DisconnectedCallback>(OnDisconnected);
            Manager.Subscribe <SteamClient.ConnectedCallback>(OnConnected);
            Manager.Subscribe <SteamUser.UpdateMachineAuthCallback>(OnMachineAuth);
            Manager.Subscribe <SteamUser.LoggedOnCallback>(OnLoggedOn);
            Manager.Subscribe <SteamApps.LicenseListCallback>(OnLicenseList);

            // internal subs
            Manager.Subscribe <SteamApps.GameConnectTokensCallback>(OnGcTokens);
        }
示例#2
0
        public void Connect()
        {
            // create our steamclient instance
            _steamClient = new SteamKit2.SteamClient();
            // create the callback manager which will route callbacks to function calls
            _manager = new CallbackManager(_steamClient);

            // get the steamuser handler, which is used for logging on after successfully connecting
            _steamUser    = _steamClient.GetHandler <SteamUser>();
            _steamApps    = _steamClient.GetHandler <SteamApps>();
            _steamFriends = _steamClient.GetHandler <SteamFriends>();

            // register a few callbacks we're interested in
            // these are registered upon creation to a callback manager, which will then route the callbacks
            // to the functions specified
            _manager.Subscribe <SteamKit2.SteamClient.ConnectedCallback>(OnConnected);
            _manager.Subscribe <SteamKit2.SteamClient.DisconnectedCallback>(OnDisconnected);

            _manager.Subscribe <SteamUser.LoggedOnCallback>(OnLoggedOn);
            _manager.Subscribe <SteamUser.LoggedOffCallback>(OnLoggedOff);

            _manager.Subscribe <SteamApps.AppOwnershipTicketCallback>(OnAppOwnershipTicketCallback);
            _manager.Subscribe <SteamApps.GameConnectTokensCallback>(OnGameConnectTokens);
            _steamClient.AddHandler(new Handler <SteamPlayer>(OnMessage));

            _isRunning = true;

            ConsoleSystem.Log("Connecting to Steam...");

            // initiate the connection
            _steamClient.Connect();

            // create our callback handling loop
            while (_isRunning)
            {
                // in order for the callbacks to get routed, they need to be handled by the manager
                _manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
            }
        }