Пример #1
0
        private void OnPacketReceived(IPEndPoint from, SteamDiscoveryTransport.Packet packet)
        {
            if (packet.clientId == this.ClientId)
            {
                return;
            }

            switch (packet.type)
            {
            case ERemoteClientBroadcastMsg.KEremoteClientBroadcastMsgDiscovery:
                CMsgRemoteClientBroadcastDiscovery discovery = CMsgRemoteClientBroadcastDiscovery.Parser.ParseFrom(packet.payload);
                BroadcastMyStatusTo(from);
                break;

            case ERemoteClientBroadcastMsg.KEremoteClientBroadcastMsgStatus:
                CMsgRemoteClientBroadcastStatus status = CMsgRemoteClientBroadcastStatus.Parser.ParseFrom(packet.payload);
                UpdateClientStatus(from, packet.clientId, packet.instanceId, status);
                break;

            case ERemoteClientBroadcastMsg.KEremoteClientBroadcastMsgOffline:
                UpdateClientStatus(from, packet.clientId, packet.instanceId, null);
                break;

            default:
                throw new IOException("Unknown message type: " + packet.type);
            }
        }
Пример #2
0
 public SteamRemote(TlsPskConnection socket, bool isServer, ulong clientId, ulong instanceId, CMsgRemoteClientBroadcastStatus myStatus)
 {
     this.socket     = socket;
     conn            = new SteamRemoteTransport(socket);
     IsServer        = isServer;
     this.clientId   = clientId;
     this.instanceId = instanceId;
     this.myStatus   = myStatus;
 }
Пример #3
0
        private async void ButtonConnect_Click(object sender, RoutedEventArgs e)
        {
            string connectAddr = InputIP.Text + ":" + InputPort.Text;
            string connectPSK  = InputPSK.Text;

            ButtonConnect.IsEnabled = false;
            Debug.WriteLine("Connect to " + connectAddr);

            var myStatus = new CMsgRemoteClientBroadcastStatus()
            {
                Version         = 8,
                MinVersion      = 6,
                ConnectPort     = SteamDiscoveryTransport.STEAM_DISCOVERY_PORT,
                Hostname        = "my-fake-name",
                EnabledServices = (uint)ERemoteClientService.KEremoteClientServiceGameStreaming,
                Ostype          = (int)EOSType.Windows10,
                Is64Bit         = true,
                Euniverse       = (int)EUniverse.Public,
                GamesRunning    = false,
            };

            myStatus.Users.Add(new CMsgRemoteClientBroadcastStatus.Types.User()
            {
                Steamid   = 76561198009414634,                  // adjust to yours
                AuthKeyId = 00000000                            // removed
            });
            byte[] psk = Hexlify.StringToByteArray(connectPSK); // you can get this (and the AuthKeyId above) in C:\Program Files (x86)\Steam\userdata\[your user id]\config\localconfig.vdf under the SharedAuth section

            TlsPskClient tlsClient = new TlsPskClient();

            tlsClient.Connect(connectAddr, "steam", psk);
            SteamRemote steamRemote = new SteamRemote(tlsClient, false, 1337, new Random().NextLong(), myStatus);

            steamRemote.MyApps.Add(new CMsgRemoteClientAppStatus.Types.AppStatus()
            {
                AppId    = 391540,
                AppState = 4
            });
            await steamRemote.Start();

            CMsgRemoteClientStartStreamResponse startResponse = await steamRemote.StartStream(new CMsgRemoteClientStartStream()
            {
                AppId              = 391540,
                LaunchOption       = -1,
                MaximumResolutionX = 1920,
                MaximumResolutionY = 1080,
                AudioChannelCount  = 2
            });

            SteamStreamClient stream = new SteamStreamClient(new IPEndPoint(IPAddress.Parse(InputIP.Text), (int)startResponse.StreamPort), startResponse.AuthToken.ToByteArray(), this);

            stream.Connect();

            unsafe
            {
                ffmpeg.av_log_set_level(ffmpeg.AV_LOG_VERBOSE);
                //ffmpeg.av_log_set_level(ffmpeg.AV_LOG_DEBUG);
                cb = libav_log;
                ffmpeg.av_log_set_callback(new av_log_set_callback_callback_func()
                {
                    Pointer = Marshal.GetFunctionPointerForDelegate(cb)
                });

                AVCodec *codec = ffmpeg.avcodec_find_decoder(AVCodecID.AV_CODEC_ID_H264);
                if (codec == null)
                {
                    throw new InvalidOperationException("Unsupported codec");
                }
                avparser         = ffmpeg.av_parser_init((int)codec->id);
                avparser->flags |= ffmpeg.PARSER_FLAG_COMPLETE_FRAMES;
                avctx            = ffmpeg.avcodec_alloc_context3(codec);
                if (ffmpeg.avcodec_open2(avctx, codec, null) < 0)
                {
                    throw new Exception("Could not open codec");
                }
            }
        }
Пример #4
0
        private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            var myStatus = new CMsgRemoteClientBroadcastStatus()
            {
                Version         = 8,
                MinVersion      = 6,
                ConnectPort     = SteamDiscoveryTransport.STEAM_DISCOVERY_PORT,
                Hostname        = "my-fake-name",
                EnabledServices = (uint)ERemoteClientService.KEremoteClientServiceGameStreaming,
                Ostype          = (int)EOSType.Windows10,
                Is64Bit         = true,
                Euniverse       = (int)EUniverse.Public,
                GamesRunning    = false,
            };

            myStatus.Users.Add(new CMsgRemoteClientBroadcastStatus.Types.User()
            {
                Steamid   = 76561198009414634,
                AuthKeyId = 00000000                                                                                    // removed
            });
            byte[] psk = Hexlify.StringToByteArray("0000000000000000000000000000000000000000000000000000000000000000"); // removed

            TlsPskClient tlsClient = new TlsPskClient();

            tlsClient.Connect("127.0.0.1:27036", "steam", psk);
            SteamRemote steamRemote = new SteamRemote(tlsClient, false, 1337, new Random().NextLong(), myStatus);

            steamRemote.MyApps.Add(new CMsgRemoteClientAppStatus.Types.AppStatus()
            {
                AppId    = 391540,
                AppState = 4
            });
            await steamRemote.Start();

            CMsgRemoteClientStartStreamResponse startResponse = await steamRemote.StartStream(new CMsgRemoteClientStartStream()
            {
                AppId              = 391540,
                LaunchOption       = -1,
                MaximumResolutionX = 1920,
                MaximumResolutionY = 1080,
                AudioChannelCount  = 2
            });

            /*Process process = new Process();
             * process.StartInfo.FileName = @"C:\Program Files (x86)\Steam\streaming_client.exe";
             * process.StartInfo.WorkingDirectory = @"C:\Program Files (x86)\Steam";
             * process.StartInfo.Arguments = "--gameid " + 391540 + " --server 127.0.0.1:" + startResponse.StreamPort + " --quality 2 " + Hexlify.ByteArrayToString(startResponse.AuthToken.ToByteArray());
             * Console.WriteLine(process.StartInfo.Arguments);
             * process.Start();*/
            SteamStreamClient stream = new SteamStreamClient(new IPEndPoint(IPAddress.Parse("127.0.0.1"), (int)startResponse.StreamPort), startResponse.AuthToken.ToByteArray(), this);

            stream.Connect();

            unsafe
            {
                ffmpeg.av_log_set_level(ffmpeg.AV_LOG_INFO);

                AVCodec *codec = ffmpeg.avcodec_find_decoder(AVCodecID.AV_CODEC_ID_H264);
                if (codec == null)
                {
                    throw new InvalidOperationException("Unsupported codec");
                }
                avctx         = ffmpeg.avcodec_alloc_context3(codec);
                avctx->width  = 1920;
                avctx->height = 1080;
                if (ffmpeg.avcodec_open2(avctx, codec, null) < 0)
                {
                    throw new Exception("Could not open codec");
                }
            }
        }
Пример #5
0
        private void UpdateClientStatus(IPEndPoint from, ulong clientId, ulong instanceId, CMsgRemoteClientBroadcastStatus status)
        {
            Client client = discovered.Where((x) => x.clientId == clientId).FirstOrDefault();

            if (client != null && client.instanceId != instanceId)
            {
                // We have a previous instance of this client, but it has since rebooted - disconnect from the stale copy
                discovered.Remove(client);
                OnClientOffline(client);
                client = null;
            }

            bool newClient = false;

            if (client == null)
            {
                // This is a new client
                client = new Client()
                {
                    clientId   = clientId,
                    instanceId = instanceId
                };
                discovered.Add(client);
                newClient = true;
            }

            if (status != null)
            {
                // We have a new status for this client
                // (could also be the first status for this client)
                client.from   = from;
                client.status = status;
                if (newClient)
                {
                    OnClientOnline(client); // do this only after status was set
                }
                OnClientStatusUpdate(client);
            }
            else
            {
                // The client sent an offline message, remove it
                discovered.Remove(client);
                if (!newClient)
                {
                    OnClientOffline(client);
                }
                client = null;
            }
        }