static async Task test_connect() { var key = "live_key"; var options = new RtmpClient.Options { // required parameters: Url = $"rtmp://live.twitch.tv/app/{key}", Context = new SerializationContext(), // optional parameters: AppName = "app", // optional app name, passed to the remote server during connect. //PageUrl = "", // optional page url, passed to the remote server during connect. //SwfUrl = "", // optional swf url, passed to the remote server during connect. //FlashVersion = "WIN 21,0,0,174", // optional flash version, paased to the remote server during connect. //ChunkLength = 4192, // optional outgoing rtmp chunk length. //Validate = (sender, certificate, chain, errors) => true // optional certificate validation callback. used only in tls connections. }; using (var client = await RtmpClient.ConnectAsync(options)) { //var exists = await client.InvokeAsync<bool>("storage", "exists", new { name = "music.pdf" }); var createStream = await client.Connection.CreateStreamAsync(); await createStream.PublishAndWaitAsync(key, "live"); } }
public static async Task Main() { Console.WriteLine($"Started: {DateTime.Now}"); RtmpStreamContent Content = new RtmpStreamContent() { RtmpUri = Rtmp }; NetStreamConfigurations configurations = new NetStreamConfigurations() { EnableSsl = true }; RtmpConnectionRequest Request = new RtmpConnectionRequest(Content, configurations); RtmpClient client = new RtmpClient(Request); await client.ConnectAsync(); await client.StreamAsync(); Console.WriteLine($"Finished: {DateTime.Now}"); Console.ReadKey(); }
/// <summary> /// /// </summary> /// <param name="regionData"></param> /// <param name="rsoAuthToken"></param> /// <param name="partnerCred">Same as AccessToken</param> /// <returns></returns> public static async Task <RtmpLoginResult> LoginRtmps(RegionData regionData, string rsoAuthToken, string partnerCred, string userName) { var client = new RiotCalls(); var rtmpClasses = HelperFunctions.GetInstances <RiotRtmpObject>(); var typeList = new List <Type>(); foreach (var rtmpClass in rtmpClasses) { typeList.Add(rtmpClass.GetType()); } var context = new SerializationContext(typeList.ToArray()); var options = new RtmpClient.Options { Url = $"rtmps://{regionData.Servers.Lcds.LcdsHost}:{regionData.Servers.Lcds.LcdsPort}", Context = context, Validate = (sender, certificate, chain, errors) => true, AppName = "LCU", PageUrl = null, SwfUrl = null, ChunkLength = 16500 }; //Pass to the rtmpclient client.RiotConnection = await RtmpClient.ConnectAsync(options); client.IsConnectedToRtmp = true; var authCred = new AuthenticationCredentials { MacAddress = LoginSystemData.MacAddress, AuthToken = rsoAuthToken, PartnerCredentials = partnerCred, OperatingSystem = LoginSystemData.OperatingSystem, Username = userName }; var loginResult = await client.Login(authCred); if (loginResult.GetType() == typeof(Session)) { client.RegionData = regionData; client.RiotSession = (Session)loginResult; return(new RtmpLoginResult(true, client, null)); } if (loginResult.GetType() != typeof(LoginFailedException)) { return(new RtmpLoginResult(false, null, null)); } client.IsConnectedToRtmp = false; await client.RiotConnection.CloseAsync(); return(new RtmpLoginResult(false, null, (LoginFailedException)loginResult)); }
static async Task <RtmpClient> BotClientAsync() { try { Console.WriteLine("Client connecting..."); var options = new RtmpClient.Options { Url = "rtmp://localhost:4000", AppName = "bot", }; var client = await RtmpClient.ConnectAsync(options); Console.WriteLine("Client connected."); //client.Disconnected += (o, s) => { ((RtmpClient)o).InvokeAsync<object>("FCUnpublish").Wait(); }; client.DispatchInvoke = s => { switch (s.MethodName) { case "a": var windowName = (string)s.Arguments[0]; botHandle = Interop.GetHandleByWindow(windowName ?? "Star Citizen"); break; case "k": var key = (char)s.Arguments[0]; Interop.PressKey((byte)key); break; case "c": Interop.ClickMouseButton(botHandle, InteropMouseButton.Left, new Point(545, 300)); break; case "bf": Interop.BringToFront(botHandle); break; default: Console.WriteLine(s.MethodName); break; } }; return(client); } catch (Exception e) { Console.WriteLine(e.Message); return(null); } }
internal void RtmpConnect() { Console.WriteLine("Connecting to RTMPS with Token: " + loginToken); var authLoginPacket = new AuthenticationCredentials(); authLoginPacket.Username = credentials.Username; authLoginPacket.Password = credentials.Password; authLoginPacket.Domain = "lolclient.lol.riotgames.com"; authLoginPacket.Locale = "en_US"; authLoginPacket.ClientVersion = ClientVersion.Get(credentials.Region); authLoginPacket.IpAddress = GetIPAddress(); authLoginPacket.AuthToken = loginToken; rtmpClient.ConnectAsync().Wait(); var loginTask = InvokeAsync <Session>("loginService", "login", authLoginPacket); loginTask.Wait(); clientSession = loginTask.Result; rtmpClient.SubscribeAsync("my-rtmps", "messagingDestination", "bc", "bc-" + clientSession.AccountSummary.AccountId.ToString()).Wait(); rtmpClient.SubscribeAsync("my-rtmps", "messagingDestination", "gn-" + clientSession.AccountSummary.AccountId.ToString(), "gn-" + clientSession.AccountSummary.AccountId.ToString()).Wait(); rtmpClient.SubscribeAsync("my-rtmps", "messagingDestination", "cn-" + clientSession.AccountSummary.AccountId.ToString(), "cn-" + clientSession.AccountSummary.AccountId.ToString()).Wait(); RtmpLogin(); var loginPacketTask = InvokeAsync <LoginDataPacket>("clientFacadeService", "getLoginDataPacketForUser"); loginPacketTask.Wait(); this.loginPacket = loginPacketTask.Result; if (loginPacket.AllSummonerData == null) { SetSummonerNameForNewAccount(); } notifications = loginPacket.BroadcastNotification.broadcastMessages; var stateTask = InvokeAsync <String>("accountService", "getAccountStateForCurrentSession"); stateTask.Wait(); String state = stateTask.Result; if (state != "ENABLED") { if (loggedIn) { RtmpLogout(); } return; //Keep the client but mark it as logged out } beginHeartbeat(); }
/// <summary> /// Connects to the /// </summary> /// <param name="User"></param> /// <param name="Shard"></param> /// <returns></returns> public async Task <bool> Connect() { //Connects to the RTMPS client await _client.ConnectAsync(); //Decrypts the users password when logging in string password = DPAPI.Decrypt(_user.Password); AuthenticationCredentials auth = new AuthenticationCredentials { Username = _user.Username, Password = password, ClientVersion = PoroServer.ClientVersion, IpAddress = "209.133.52.232", Locale = _shard.Locale, Domain = "lolclient.lol.riotgames.com", AuthToken = GetAuthKey(_user.Username, password, _shard.LoginQueue) }; //Gets the current login session Session login = await Login(_client, auth); _accountId = login.Summary.AccountId; //Subscribes to server messages await _client.SubscribeAsync("my-rtmps", "messagingDestination", "bc", "bc-" + login.Summary.AccountId.ToString()); await _client.SubscribeAsync("my-rtmps", "messagingDestination", "gn-" + login.Summary.AccountId.ToString(), "gn-" + login.Summary.AccountId.ToString()); await _client.SubscribeAsync("my-rtmps", "messagingDestination", "cn-" + login.Summary.AccountId.ToString(), "cn-" + login.Summary.AccountId.ToString()); bool LoggedIn = await _client.LoginAsync(_user.Username.ToLower(), login.Token); //TODO: Find easier way of getting summoner name and id without having to download a huge packet LoginDataPacket dataPacket = await GetLoginPacket(_client); _packet = dataPacket; _summonerId = dataPacket.AllSummonerData.Summoner.SumId; _summonerName = dataPacket.AllSummonerData.Summoner.Name; return(LoggedIn); }
private static async Task MainAsync() { // Socket s = new Socket(AddressFamily.Ipx, SocketType.Stream, ProtocolType.IP); // await s.ConnectAsync( const string uri = "rtmp://x.kipod.com/live/51:902b3459783c:6?signature=JJa-cs2s660ec4FEjugXHA&expires=1441112256"; AKUtils.Trace(uri); var client = new RtmpClient( new Uri(uri), new SerializationContext(), ObjectEncoding.Amf3); // connect to the server await client.ConnectAsync(); // await client.(); // call a remote service // var songs = await client.InvokeAsync<string[]>("musicalService", "findSongs"); var streamId = await client.CreateStreamInvokeAsync(); var play = await client.PlayInvokeAsync();//<object>("play", "51:902b3459783c:6:live"); }
static async Task test_client_server() { var serverOptions = new RtmpServer.Options { Url = "rtmp://localhost:4000/key", Context = new SerializationContext(), }; using (var server = await RtmpServer.ConnectAsync(serverOptions, x => { })) { var clientOptions = new RtmpClient.Options { Url = "rtmp://localhost:4000/key", Context = new SerializationContext(), }; using (var client = await RtmpClient.ConnectAsync(clientOptions)) { Console.WriteLine("Connect"); } } }
internal async Task Login(AuthResult auth) { if (!Init.IsCompleted) { await Init; } if (auth.Content.Status != "LOGIN") { throw new ArgumentException("Invalid auth credentials"); } var context = Riot.Services.Service.RegisterObjects(); rtmp = new RtmpClient(new Uri("rtmps://" + Region.Current.MainServer + ":2099"), context, ObjectEncoding.Amf3); rtmp.MessageReceived += Rtmp_MessageReceived; rtmp.Disconnected += Rtmp_Disconnected; await rtmp.ConnectAsync(); chat.Connect(auth); LoginSession session = null; do { try { var creds = auth.GetAuthCredentials(); creds.ClientVersion = clientVersion; session = await LoginService.Login(creds); } catch (InvocationException x) when(x.RootCause is ClientVersionMismatchException) { var inner = (ClientVersionMismatchException)x.RootCause; clientVersion = (string)inner.SubstitutionArguments[1]; Log("Patch (DDragon outdated): " + clientVersion); } } while (session == null); string bc = $"bc-{session.AccountSummary.AccountId}"; string gn = $"gn-{session.AccountSummary.AccountId}"; string cn = $"cn-{session.AccountSummary.AccountId}"; await Task.WhenAll( rtmp.SubscribeAsync("my-rtmps", "messagingDestination", "bc", bc), rtmp.SubscribeAsync("my-rtmps", "messagingDestination", gn, gn), rtmp.SubscribeAsync("my-rtmps", "messagingDestination", cn, cn) ); await rtmp.LoginAsync(auth.Username.ToLower(), session.Token); string state = await AccountService.GetAccountState(); if (state != "ENABLED") { Log(state); throw new AuthenticationException("Not Enabled: " + state); } this.LoginQueue = auth.Content; this.loginSession = session; this.Me = await summoner.Connect(session); try { Authed?.Invoke(this, EventArgs.Empty); } catch (Exception x) { Log("Caught exception while dispatching auth: " + x); } BackEndServer.Async("/kappa/defer/auth", new JSONObject()); new Thread(HeartBeatLoop) { IsBackground = true }.Start(); }
public async Task <bool> ConnectAndLogin() { if (_useGarena) { //this.RaiseError("Garena servers are not yet supported.", ErrorType.Connect); //return false; } SetDefaultsParams(); RtmpClient = new RtmpClient(new Uri(_gameServer), SerializationContext, ObjectEncoding.Amf3); // ISSUE: reference to a compiler-generated field RtmpClient.MessageReceived += OnMessageReceived; LoginQueue loginQueue = new LoginQueue(Username, Password, Region); loginQueue.OnAuthFailed += message => RaiseError(message, ErrorType.Login); loginQueue.OnUpdateStatusMessage += (sender, s) => { if (OnUpdateStatusMessage == null) { return; } object sender1 = sender; string e = s; OnUpdateStatusMessage(sender1, e); }; if (!await loginQueue.GetAuthToken().ConfigureAwait(false)) { return(false); } this.AuthToken = loginQueue.AuthToken; this.UserId = loginQueue.UserId; Stopwatch sw = new Stopwatch(); sw.Start(); try { while (sw.ElapsedMilliseconds / 1000L <= ConnectTimeoutSeconds) { try { AsObject asObject = await RtmpClient.ConnectAsync().ConfigureAwait(false); sw.Stop(); goto label_13; } catch (Exception ex) { Tools.Log(ex.StackTrace); } await Task.Delay(5000).ConfigureAwait(false); continue; label_13: OnConnect?.Invoke((object)this, EventArgs.Empty); this.RtmpClient.SetChunkSize(int.MaxValue); AuthenticationCredentials cred = new AuthenticationCredentials() { Username = Username, Password = Password, ClientVersion = ClientVersion, Domain = "lolclient.lol.riotgames.com", Locale = _locale, OperatingSystem = "Windows 10", AuthToken = AuthToken }; if (_useGarena) { cred.PartnerCredentials = loginQueue.Token; cred.Username = loginQueue.User;//UserId cred.Password = null; } this.Session = await this.Login(cred).ConfigureAwait(false); string[] strArray = new string[3] { "gn", "cn", "bc" }; for (int index = 0; index < strArray.Length; ++index) { strArray[index] = string.Format("{0}-{1}", strArray[index], Session.AccountSummary.AccountId); } bool[] flagArray = await Task.WhenAll(new Task <bool>[3] { RtmpClient.SubscribeAsync("my-rtmps", "messagingDestination", strArray[0], strArray[0]), RtmpClient.SubscribeAsync("my-rtmps", "messagingDestination", strArray[1], strArray[1]), RtmpClient.SubscribeAsync("my-rtmps", "messagingDestination", "bc", strArray[2]) }).ConfigureAwait(false); if (_useGarena) { IsConnected = await RtmpClient.LoginAsync(cred.Username, Session.Token).ConfigureAwait(false); } else { IsConnected = await RtmpClient.LoginAsync(Username.ToLower(), Session.Token).ConfigureAwait(false); } //IsConnected = await RtmpClient.LoginAsync(Username.ToLower(), Session.Token).ConfigureAwait(false); _heartbeatTimer = new Timer(); _heartbeatTimer.Elapsed += new ElapsedEventHandler(DoHeartBeat); _heartbeatTimer.Interval = 120000.0; _heartbeatTimer.Start(); _uptime = DateTime.Now; OnLogin?.Invoke(Username); return(true); } sw.Stop(); RaiseError("Connection failed.", ErrorType.Connect); return(false); } catch (InvocationException ex) { if (ex.RootCause != null && ex.RootCause.GetType() == typeof(LoginFailedException)) { LoginFailedException rootCause = (LoginFailedException)ex.RootCause; string errorCode = rootCause.ErrorCode; if (!(errorCode == "LOGIN-0018")) { if (errorCode == "LOGIN-0019") { RaiseError("User blocked.", ErrorType.Login); return(false); } this.RaiseError(string.Format("{0}: {1}", "LoginFailedException", rootCause.ErrorCode).Trim(), ErrorType.Login); return(false); } RaiseError("Password change required.", ErrorType.Password); return(false); } if (!string.IsNullOrEmpty(ex.Message)) { RaiseError(ex.Message, ErrorType.Invoke); return(false); } } catch (Exception ex) { Tools.Log(ex.StackTrace); } finally { sw.Stop(); } this.RaiseError("Login failed with unknown error. Try again later.", ErrorType.Login); return(false); }
public async void Connect() { await _client.ConnectAsync(); }
public async Task <bool> Connect(string user, string pass) { try { _user = user; await _client.ConnectAsync(); var cred = new AuthenticationCredentials(); cred.Username = user; cred.Password = pass; cred.ClientVersion = _version; cred.Domain = "lolclient.lol.riotgames.com"; cred.IpAddress = GetIpAddress(); cred.Locale = "en_US"; cred.AuthToken = GetAuthToken(_region, user, pass); if (cred.AuthToken == "RETRY") { Log.Error("[{0}] Login queue error!", _user); Disconnect(); return(await Connect(user, pass)); } _session = await Login(cred); await _client.SubscribeAsync("my-rtmps", "messagingDestination", "bc", "bc-" + _session.AccountSummary.AccountId.ToString()); await _client.SubscribeAsync("my-rtmps", "messagingDestination", "gn-" + _session.AccountSummary.AccountId.ToString(), "gn-" + _session.AccountSummary.AccountId.ToString()); await _client.SubscribeAsync("my-rtmps", "messagingDestination", "cn-" + _session.AccountSummary.AccountId.ToString(), "cn-" + _session.AccountSummary.AccountId.ToString()); var loggedIn = await _client.LoginAsync(user.ToLower(), _session.Token); _auth = true; //Log.Write("[{0}] Logged in!", _session.AccountSummary.Username); _heartbeatTimer = new Timer(); _heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat); _heartbeatTimer.Interval = 120000; _heartbeatTimer.Start(); _uptime = DateTime.Now; return(true); } catch (InvocationException e) { } catch (ClientDisconnectedException) { } catch (System.Net.WebException ex) { var res = (System.Net.HttpWebResponse)ex.Response; if (res != null && (int)res.StatusCode == 403) { using (var reader = new StreamReader(res.GetResponseStream())) { var body = reader.ReadToEnd(); var jsonSerializer = new JavaScriptSerializer(); var json = jsonSerializer.Deserialize <Dictionary <string, object> >(body); Log.Write("[{0}] Error on login: {1}", user, json["reason"]); if (Convert.ToString(json["reason"]) == "attempt_rate_too_fast") { Log.Write("[{0}] Waiting 5 seconds due to throttle from Riot.", user); System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5)); //Log.Close(); //Process.Start(Environment.CurrentDirectory + "\\Summoning.exe"); //Environment.Exit(0); } } return(false); } } catch (Exception e) { Log.Write("[{0}] Exception while authing: {1}", user, e.Message); return(false); } _client.Close(); return(await Connect(user, pass)); }