Beispiel #1
0
        public override void WriteExternal(IDataOutput output)
        {
            base.WriteExternal(output);

            if (CorrelationIdBytes == null)
            {
                CorrelationIdBytes = RtmpUtil.ToByteArray(CorrelationId);
            }

            int flag = 0;

            if (CorrelationId != null && CorrelationIdBytes == null)
            {
                flag |= CORRELATION_ID_FLAG;
            }
            if (CorrelationIdBytes != null)
            {
                flag |= CORRELATION_ID_BYTES_FLAG;
            }

            output.WriteByte((byte)flag);

            if (CorrelationId != null && CorrelationIdBytes == null)
            {
                output.WriteObject(CorrelationId);
            }
            if (CorrelationIdBytes != null)
            {
                output.WriteObject(CorrelationIdBytes);
            }
        }
        private void SendLoginInfo()
        {
            ASObject body = new ASObject();

            body.Add("username", Username.ToLower());
            body.Add("password", Password);
            body.Add("authToken", AuthToken);
            body.Add("clientVersion", ClientVersion);
            body.Add("ipAddress", IPAddress);
            body.Add("locale", "en_US");
            body.Add("domain", "lolclient.lol.riotgames.com");
            body.Add("operatingSystem", "LolService");
            body.Add("securityAnswer", null);
            body.Add("oldPassword", null);
            body.Add("partnerCredentials", null);
            body.TypeName = "com.riotgames.platform.login.AuthenticationCredentials";

            Notify result = base.InvokeRemotingMessage("loginService", "login", new object[] { body });

            if (RtmpUtil.IsError(result))
            {
                ErrorMessage error = RtmpUtil.GetError(result);
                Form1.Log("Error = " + error.faultString);
                return;
            }

            ASObject args           = (ASObject)RtmpUtil.GetBodies(result).FirstOrDefault().Item1;
            ASObject AccountSummary = (ASObject)args["accountSummary"];

            this.SessionToken = (string)args["token"];
            this.AccountID    = Convert.ToInt32(AccountSummary["accountId"]);
            Form1.Log("SessionToken = " + SessionToken);
            Form1.Log("Account ID: " + AccountID);
        }
        private void PingOperation()
        {
            var Message = RtmpUtil.MakeCommandMessage("", CommandMessage.ClientPingOperation, DSId, new ASObject()
            {
                TypeName = null
            });
            var inv = new Invoke();

            inv.ServiceCall = new PendingCall(null, "connect", new object[] { false, "nil", "", Message });

            inv.ConnectionParameters = new Dictionary <string, object>();
            inv.ConnectionParameters.Add("app", "");
            inv.ConnectionParameters.Add("flashVer", "WIN 10,1,85,3");
            inv.ConnectionParameters.Add("swfUrl", "app:/mod_ser.dat");
            inv.ConnectionParameters.Add("tcUrl", "rtmps://" + Server + ":2099");
            inv.ConnectionParameters.Add("fpad", false);
            inv.ConnectionParameters.Add("capabilities", 239);
            inv.ConnectionParameters.Add("audioCodecs", 3191);
            inv.ConnectionParameters.Add("videoCodecs", 252);
            inv.ConnectionParameters.Add("videoFunction", 1);
            inv.ConnectionParameters.Add("pageUrl", null);
            inv.ConnectionParameters.Add("objectEncoding", 3);
            inv.EventType = (EventType)2;

            Notify   reply = base.Call(inv);
            ASObject args  = reply.ServiceCall.Arguments[0] as ASObject;

            DSId = args["id"].ToString();
            Form1.Log("DSId = " + DSId);
        }
Beispiel #4
0
        public virtual void OnProcessResults(object sender, Notify results)
        {
            var bodies = RtmpUtil.GetBodies(results);

            foreach (var obj in bodies)
            {
                OnProcessObject(this, obj.Item1, obj.Item2);
            }
        }
Beispiel #5
0
        public virtual void ReadExternal(IDataInput input)
        {
            var flags = ReadFlags(input);

            for (int i = 0; i < flags.Count; i++)
            {
                int bits = 0;
                if (i == 0)
                {
                    if ((flags[i] & BODY_FLAG) != 0)
                    {
                        Body = input.ReadObject();
                    }
                    if ((flags[i] & CLIENT_ID_FLAG) != 0)
                    {
                        ClientId = input.ReadObject() as string;
                    }
                    if ((flags[i] & DESTINATION_FLAG) != 0)
                    {
                        Destination = input.ReadObject() as string;
                    }
                    if ((flags[i] & HEADERS_FLAG) != 0)
                    {
                        Headers = input.ReadObject();
                    }
                    if ((flags[i] & MESSAGE_ID_FLAG) != 0)
                    {
                        MessageId = input.ReadObject() as string;
                    }
                    if ((flags[i] & TIMESTAMP_FLAG) != 0)
                    {
                        TimeStamp = Convert.ToInt64(input.ReadObject());
                    }
                    if ((flags[i] & TIME_TO_LIVE_FLAG) != 0)
                    {
                        TimeToLive = Convert.ToInt64(input.ReadObject());
                    }
                    bits = 7;
                }
                else if (i == 1)
                {
                    if ((flags[i] & CLIENT_ID_BYTES_FLAG) != 0)
                    {
                        ClientIdBytes = input.ReadObject() as ByteArray;
                        ClientId      = RtmpUtil.FromByteArray(ClientIdBytes);
                    }
                    if ((flags[i] & MESSAGE_ID_BYTES_FLAG) != 0)
                    {
                        MessageIdBytes = input.ReadObject() as ByteArray;
                        MessageId      = RtmpUtil.FromByteArray(MessageIdBytes);
                    }
                    bits = 2;
                }
                ReadRemaining(input, flags[i], bits);
            }
        }
Beispiel #6
0
        protected override void OnReceive(byte[] buffer, int idx, int len)
        {
            byte[] ReceiveBuffer = new byte[len];
            Array.Copy(buffer, idx, ReceiveBuffer, 0, len);

            var objs = RtmpProtocolDecoder.DecodeBuffer(remotecontext, new ByteBuffer(new MemoryStream(ReceiveBuffer)));

            if (objs != null)
            {
                foreach (var obj in objs)
                {
                    RtmpPacket packet = obj as RtmpPacket;
                    if (packet != null)
                    {
                        var result = packet.Message as Notify;
                        if (result != null)
                        {
                            CallResultWait callresult = null;
                            if (RtmpUtil.IsResult(result))
                            {
                                lock (WaitLock)
                                {
                                    int fidx = WaitInvokeList.FindIndex(crw => crw.Call.InvokeId == result.InvokeId);
                                    if (fidx != -1)
                                    {
                                        callresult = WaitInvokeList[fidx];
                                        WaitInvokeList.RemoveAt(fidx);
                                    }
                                }

                                if (callresult != null)
                                {
                                    callresult.Result = result;
                                    callresult.Wait.Set();

                                    if (!callresult.Blocking)
                                    {
                                        OnCall(callresult.Call, callresult.Result);
                                    }
                                }
                                else
                                {
                                    OnNotify(result);
                                }
                            }
                            else
                            {
                                OnNotify(result);
                            }
                        }
                    }
                }
            }
        }
Beispiel #7
0
        public Notify InvokeRemotingMessage(string service, string operation, params object[] args)
        {
            var msg = new RemotingMessage();

            msg.operation   = operation;
            msg.destination = service;
            msg.headers["DSRequestTimeout"] = 60;
            msg.headers["DSId"]             = RtmpUtil.RandomUidString();
            msg.headers["DSEndpoint"]       = "my-rtmps";
            msg.body      = args;
            msg.messageId = RtmpUtil.RandomUidString();

            return(Invoke(msg));
        }
Beispiel #8
0
        /// <summary>
        /// Used to invoke a service which you don't know what it returns.
        /// </summary>
        /// <param name="service"></param>
        /// <param name="operation"></param>
        /// <param name="args"></param>
        /// <returns>ASObject body</returns>
        public object InvokeServiceUnknown(string service, string operation, params object[] args)
        {
            var msg = new RemotingMessage();

            msg.operation   = operation;
            msg.destination = service;
            msg.headers["DSRequestTimeout"] = 60;
            msg.headers["DSId"]             = RtmpUtil.RandomUidString();
            msg.headers["DSEndpoint"]       = "my-rtmps";
            msg.body      = args;
            msg.messageId = RtmpUtil.RandomUidString();

            string endpoint = service + "." + operation;

            var result = Host.Call(msg);

            if (result == null)
            {
                StaticLogger.Warning(string.Format("Invoking {0} returned null", endpoint));
                return(null);
            }

            if (RtmpUtil.IsError(result))
            {
                var error       = RtmpUtil.GetError(result);
                var errordetail = error != null && error.faultDetail != null?string.Format(" [{0}]", error.faultDetail) : "";

                var errorstr = error != null && error.faultString != null?string.Format(", {0}", error.faultString) : "";

                StaticLogger.Warning(string.Format(
                                         "{0} returned an error{1}{2}",
                                         endpoint,
                                         errorstr,
                                         errordetail
                                         ));
                return(null);
            }

            var body = RtmpUtil.GetBodies(result).FirstOrDefault();

            if (body == null)
            {
                StaticLogger.Debug(endpoint + " RtmpUtil.GetBodies returned null");
                return(null);
            }

            return(body.Item1);
        }
        private void LoginOperation()
        {
            byte[] LoginBody = System.Text.Encoding.UTF8.GetBytes(Username.ToLower() + ":" + SessionToken);
            var    Invoke    = base.InvokeCommandMessage("auth", CommandMessage.LoginOperation, Convert.ToBase64String(LoginBody), DSId);
            var    Body      = RtmpUtil.GetBodies(Invoke).FirstOrDefault();

            if (Body == null || !(Body.Item1 is string))
            {
                Form1.Log("Invalid login");
                return;
            }
            base.InvokeSubscribeMessage("bc", "bc-" + AccountID);
            base.InvokeSubscribeMessage("cn-" + AccountID, "cn-" + AccountID);
            base.InvokeSubscribeMessage("gn-" + AccountID, "gn-" + AccountID);
            LoggedIn  = true;
            Heartbeat = new LCDSHeartbeat(this);
        }
Beispiel #10
0
        protected Notify InvokeCommandMessage(string service, int operation, object body, string DSId)
        {
            var msg = new CommandMessage();

            msg.operation     = operation;
            msg.correlationId = "";
            msg.timestamp     = 0;
            msg.clientId      = null;
            msg.timeToLive    = 0;
            msg.messageId     = RtmpUtil.RandomUidString();
            msg.destination   = service;
            msg.body          = body;
            msg.SetHeader("DSId", DSId);
            msg.SetHeader("DSEndpoint", "my-rtmps");

            return(Invoke(msg));
        }
Beispiel #11
0
        private void dumpToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (CallView.SelectedItems.Count < 1)
            {
                return;
            }

            var notifies = CallView.SelectedItems[0].Tag as List <Notify>;

            if (notifies == null)
            {
                return;
            }

            using (var sfd = new SaveFileDialog())
            {
                sfd.Filter           = "text files (*.txt)|*.txt";
                sfd.InitialDirectory = Application.StartupPath;
                sfd.RestoreDirectory = true;

                if (sfd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                //TypeName in ASObject is not serialized(Most likely due to inheriting Dictionary?).
                //Lets manually add the TypeName field to the dictionary.
                foreach (var notify in notifies)
                {
                    var bodies = RtmpUtil.GetBodies(notify);
                    foreach (var body in bodies)
                    {
                        AddMissingTypeNames(body.Item1);
                    }
                }

                using (var sw = new StreamWriter(sfd.OpenFile()))
                {
                    sw.Write(JsonConvert.SerializeObject(notifies, Formatting.Indented, new JsonSerializerSettings()
                    {
                        TypeNameHandling = TypeNameHandling.All
                    }));
                }
            }
        }
Beispiel #12
0
        public override void ReadExternal(IDataInput input)
        {
            base.ReadExternal(input);
            var flags = ReadFlags(input);

            for (int i = 0; i < flags.Count; i++)
            {
                int bits = 0;
                if (i == 0)
                {
                    if ((flags[i] & CORRELATION_ID_FLAG) != 0)
                    {
                        CorrelationId = input.ReadObject() as string;
                    }
                    if ((flags[i] & CORRELATION_ID_BYTES_FLAG) != 0)
                    {
                        CorrelationId = RtmpUtil.FromByteArray(input.ReadObject() as ByteArray);
                    }
                    bits = 2;
                }
                ReadRemaining(input, flags[i], bits);
            }
        }
Beispiel #13
0
        private void CallView_SelectedIndexChanged(object sender, EventArgs e)
        {
            CallTree.Nodes.Clear();

            if (CallView.SelectedItems.Count < 1)
            {
                return;
            }

            var notifies = CallView.SelectedItems[0].Tag as List <Notify>;

            if (notifies == null)
            {
                return;
            }

            foreach (var notify in notifies)
            {
                var children = new List <TreeNode>();
                var bodies   = RtmpUtil.GetBodies(notify);
                foreach (var body in bodies)
                {
                    children.Add(GetNode(body.Item1) ?? new TreeNode(body.Item1 != null ? body.Item1.ToString() : ""));
                }

                CallTree.Nodes.Add(new TreeNode(!RtmpUtil.IsResult(notify) ? "Call" : "Return", children.ToArray()));
            }

            foreach (TreeNode node in CallTree.Nodes)
            {
                node.Expand();
                foreach (TreeNode node2 in node.Nodes)
                {
                    node2.Expand();
                }
            }
        }
Beispiel #14
0
        public virtual void WriteExternal(IDataOutput output)
        {
            if (ClientIdBytes == null)
            {
                ClientIdBytes = RtmpUtil.ToByteArray(ClientId);
            }
            if (MessageIdBytes == null)
            {
                MessageIdBytes = RtmpUtil.ToByteArray(MessageId);
            }

            int firstflags = 0;

            if (Body != null)
            {
                firstflags |= BODY_FLAG;
            }
            if (ClientId != null && ClientIdBytes == null)
            {
                firstflags |= CLIENT_ID_FLAG;
            }
            if (Destination != null)
            {
                firstflags |= DESTINATION_FLAG;
            }
            if (Headers != null)
            {
                firstflags |= HEADERS_FLAG;
            }
            if (MessageId != null && MessageIdBytes == null)
            {
                firstflags |= MESSAGE_ID_FLAG;
            }
            if (TimeStamp != 0)
            {
                firstflags |= TIMESTAMP_FLAG;
            }
            if (TimeToLive != 0)
            {
                firstflags |= TIME_TO_LIVE_FLAG;
            }

            int secondflags = 0;

            if (ClientIdBytes != null)
            {
                secondflags |= CLIENT_ID_BYTES_FLAG;
            }
            if (MessageIdBytes != null)
            {
                secondflags |= MESSAGE_ID_BYTES_FLAG;
            }

            if (secondflags != 0)
            {
                firstflags |= HAS_NEXT_FLAG;
            }

            output.WriteByte((byte)firstflags);
            if (secondflags != 0)
            {
                output.WriteByte((byte)secondflags);
            }

            if (Body != null)
            {
                output.WriteObject(Body);
            }
            if (ClientId != null && ClientIdBytes == null)
            {
                output.WriteObject(ClientId);
            }
            if (Destination != null)
            {
                output.WriteObject(Destination);
            }
            if (Headers != null)
            {
                output.WriteObject(Headers);
            }
            if (MessageId != null && MessageIdBytes == null)
            {
                output.WriteObject(MessageId);
            }
            if (TimeStamp != 0)
            {
                output.WriteObject(TimeStamp);
            }
            if (TimeToLive != 0)
            {
                output.WriteObject(TimeToLive);
            }

            if (ClientIdBytes != null)
            {
                output.WriteObject(ClientIdBytes);
            }
            if (MessageIdBytes != null)
            {
                output.WriteObject(MessageIdBytes);
            }
        }
Beispiel #15
0
        public T InvokeService <T>(string service, string operation, params object[] args) where T : class
        {
            var msg = new RemotingMessage();

            msg.operation   = operation;
            msg.destination = service;
            msg.headers["DSRequestTimeout"] = 60;
            msg.headers["DSId"]             = RtmpUtil.RandomUidString();
            msg.headers["DSEndpoint"]       = "my-rtmps";
            msg.body      = args;
            msg.messageId = RtmpUtil.RandomUidString();

            string endpoint = service + "." + operation;

            var result = Host.Call(msg);

            if (result == null)
            {
                StaticLogger.Warning(string.Format("Invoking {0} returned null", endpoint));
                return(null);
            }

            if (RtmpUtil.IsError(result))
            {
                var error       = RtmpUtil.GetError(result);
                var errordetail = error != null && error.faultDetail != null?string.Format(" [{0}]", error.faultDetail) : "";

                var errorstr = error != null && error.faultString != null?string.Format(", {0}", error.faultString) : "";

                StaticLogger.Warning(string.Format(
                                         "{0} returned an error{1}{2}",
                                         endpoint,
                                         errorstr,
                                         errordetail
                                         ));
                return(null);
            }

            var body = RtmpUtil.GetBodies(result).FirstOrDefault();

            if (body == null)
            {
                StaticLogger.Debug(endpoint + " RtmpUtil.GetBodies returned null");
                return(null);
            }

            if (body.Item1 == null)
            {
                StaticLogger.Debug(endpoint + " Body.Item1 returned null");
                return(null);
            }

            object obj = null;

            if (body.Item1 is ASObject)
            {
                var ao = (ASObject)body.Item1;
                obj = MessageTranslator.Instance.GetObject <T>(ao);
                if (obj == null)
                {
                    StaticLogger.Debug(endpoint + " expected " + typeof(T) + ", got " + ao.TypeName);
                    return(null);
                }
            }
            else if (body.Item1 is ArrayCollection)
            {
                try
                {
                    obj = Activator.CreateInstance(typeof(T), (ArrayCollection)body.Item1);
                }
                catch (Exception ex)
                {
                    StaticLogger.Warning(endpoint + " failed to construct " + typeof(T));
                    StaticLogger.Debug(ex);
                    return(null);
                }
            }
            else
            {
                StaticLogger.Debug(endpoint + " unknown object " + body.Item1.GetType());
                return(null);
            }

            if (obj is MessageObject)
            {
                ((MessageObject)obj).TimeStamp = body.Item2;
            }

            return((T)obj);
        }
Beispiel #16
0
        /// <summary>
        /// Replaces the invokeid
        /// </summary>
        /// <param name="notify"></param>
        protected void InternalReceive(Notify notify)
        {
            if (RtmpUtil.IsResult(notify))
            {
                int ourid = notify.InvokeId;

                CallResultWait callresult = null;
                lock (WaitLock)
                {
                    if (WaitInvokeList != null)
                    {
                        int idx = WaitInvokeList.FindIndex(crw => crw.Call.InvokeId == ourid);
                        if (idx != -1)
                        {
                            callresult = WaitInvokeList[idx];
                            WaitInvokeList.RemoveAt(idx);
                        }
                    }
                }

                //InvokeId was found in the waitlist, that means its one of our calls.
                if (callresult != null)
                {
                    callresult.Result = notify;
                    callresult.Wait.Set();

                    //Not blocking, lets send it to the handler instead.
                    if (!callresult.Blocking)
                    {
                        OnCall(callresult.Call, callresult.Result);
                    }

                    return;                     //Return, we don't want LoL receiving the message.
                }

                int theirid;
                lock (InvokeIds)
                {
                    if (!InvokeIds.TryGetValue(ourid, out theirid))
                    {
                        StaticLogger.Error(string.Format("Call id not found for {0}", notify));
                        return;
                    }
                    InvokeIds.Remove(ourid);
                }
                notify.InvokeId = theirid;
            }

            var buf = RtmpProtocolEncoder.Encode(remotecontext, CreatePacket(notify));

            if (buf == null)
            {
                StaticLogger.Fatal("Unable to encode " + notify);
            }
            else
            {
                var buff = buf.ToArray();
                if (logtofiles)
                {
                    using (var fs = File.Open("recv.dmp", FileMode.Append, FileAccess.Write))
                    {
                        fs.Write(buff, 0, buff.Length);
                    }
                }
                if (encode)
                {
                    base.OnReceive(buff, 0, buff.Length);
                }
            }
        }
Beispiel #17
0
        protected override void OnReceive(byte[] buffer, int idx, int len)
        {
            StaticLogger.Trace(string.Format("Recv {0} bytes", len));

            if (logtofiles)
            {
                using (var fs = File.Open("realrecv.dmp", FileMode.Append, FileAccess.Write))
                {
                    fs.Write(buffer, idx, len);
                }
            }

            receivebuffer.Append(buffer, idx, len);

            var objs = RtmpProtocolDecoder.DecodeBuffer(remotecontext, receivebuffer);

            if (objs != null)
            {
                foreach (var obj in objs)
                {
                    var pck = obj as RtmpPacket;
                    if (pck != null)
                    {
                        var result = pck.Message as Notify;
                        if (result != null)
                        {
                            Notify inv = null;
                            if (RtmpUtil.IsResult(result))
                            {
                                lock (InvokeList)
                                {
                                    int fidx = InvokeList.FindIndex(i => i.InvokeId == result.InvokeId);
                                    if (fidx != -1)
                                    {
                                        inv = InvokeList[fidx];
                                        InvokeList.RemoveAt(fidx);
                                    }
                                }

                                if (inv != null)
                                {
                                    OnCall(inv, result);

                                    StaticLogger.Trace(
                                        string.Format(
                                            "Ret  ({0}) (Id:{1})",
                                            string.Join(", ", inv.ServiceCall.Arguments.Select(o => o.ToString())),
                                            pck.Header.ChannelId
                                            )
                                        );
                                }
                            }
                            else
                            {
                                OnNotify(result);
                            }
                        }
                        else
                        {
                            StaticLogger.Trace(string.Format("Recv {0} (Id:{1})", pck.Message, pck.Header.ChannelId));
                        }
                    }
                    else if (obj is ByteBuffer)
                    {
                        //Just handshakes, ignore
                    }
                    else
                    {
                        StaticLogger.Warning(string.Format("Unknown object {0}", obj.GetType()));
                    }

                    if (obj != null && encode)
                    {
                        if (pck != null && pck.Message is Notify)
                        {
                            InternalReceive((Notify)pck.Message);
                            remotecontext.ObjectEncoding = ObjectEncoding.AMF3;
                        }
                        else
                        {
                            var buf = RtmpProtocolEncoder.Encode(remotecontext, obj);
                            if (buf == null)
                            {
                                StaticLogger.Fatal("Unable to encode " + obj);
                            }
                            else
                            {
                                var buff = buf.ToArray();
                                if (logtofiles)
                                {
                                    using (var fs = File.Open("recv.dmp", FileMode.Append, FileAccess.Write))
                                    {
                                        fs.Write(buff, 0, buff.Length);
                                    }
                                }
                                if (encode)
                                {
                                    base.OnReceive(buff, 0, buff.Length);
                                }
                            }
                        }
                    }
                }
            }

            if (!encode)
            {
                base.OnReceive(buffer, idx, len);
            }
        }