/// <summary> /// Reads the object AM f0. /// </summary> /// <returns></returns> /// <exception cref="System.NotImplementedException">AMF0 type not supported: + b</exception> private static TypedObject ReadObjectAMF0() { TypedObject body = new TypedObject("Body"); string key; while (!(key = ReadStringAMF0()).Equals("")) { byte b = ReadByte(); if (b == 0x00) { body.Add(key, ReadDouble()); } else if (b == 0x02) { body.Add(key, ReadStringAMF0()); } else if (b == 0x05) { body.Add(key, null); } else { throw new NotImplementedException("AMF0 type not supported: " + b); } } ReadByte(); // Skip object end marker return(body); }
/// <summary> /// Decodes the invoke. /// </summary> /// <param name="data">The data.</param> /// <returns></returns> /// <exception cref="System.Exception">Did not consume entire buffer: + dataPos + of + dataBuffer.Length</exception> public static TypedObject DecodeInvoke(byte[] data) { Reset(); dataBuffer = data; dataPos = 0; TypedObject result = new TypedObject("Invoke"); if (dataBuffer[0] == 0x00) { dataPos++; result.Add("version", 0x00); } result.Add("result", DecodeAMF0()); result.Add("invokeId", DecodeAMF0()); result.Add("serviceCall", DecodeAMF0()); result.Add("data", DecodeAMF0()); if (dataPos != dataBuffer.Length) { throw new Exception("Did not consume entire buffer: " + dataPos + " of " + dataBuffer.Length); } return(result); }
/// <summary> /// Decodes the connect. /// </summary> /// <param name="data">The data.</param> /// <returns></returns> /// <exception cref="System.Exception"> /// There is other data in the buffer! /// or /// Did not consume entire buffer: + dataPos + of + dataBuffer.Length /// </exception> public static TypedObject DecodeConnect(byte[] data) { Reset(); dataBuffer = data; dataPos = 0; TypedObject result = new TypedObject("Invoke"); result.Add("result", DecodeAMF0()); result.Add("invokeId", DecodeAMF0()); result.Add("serviceCall", DecodeAMF0()); result.Add("data", DecodeAMF0()); if (dataPos != dataBuffer.Length) { for (int i = dataPos; i < data.Length; i++) { if (ReadByte() != '\0') { throw new Exception("There is other data in the buffer!"); } } } if (dataPos != dataBuffer.Length) { throw new Exception("Did not consume entire buffer: " + dataPos + " of " + dataBuffer.Length); } return(result); }
public TypedObject DecodeInvoke(byte[] data) { Reset(); dataBuffer = data; dataPos = 0; TypedObject result = new TypedObject("Invoke"); if (dataBuffer[0] == 0x00) { dataPos++; result.Add("version", 0x00); } result.Add("result", DecodeAMF0()); result.Add("invokeId", DecodeAMF0()); result.Add("serviceCall", DecodeAMF0()); result.Add("data", DecodeAMF0()); if (dataPos != dataBuffer.Length) { throw new Exception("Did not consume entire buffer: " + dataPos + " of " + dataBuffer.Length); } string[] typeNames = new string[classDefinitions.Count]; for (int i = 0; i < classDefinitions.Count; i++) { typeNames[i] = classDefinitions[i].type; } return(result); }
public async Task <object> Subscribe(string service, double accountId) { TypedObject body = WrapBody(new TypedObject(), "messagingDestination", 0); body.type = "flex.messaging.messages.CommandMessage"; TypedObject headers = body.GetTO("headers"); if (service == "bc") { headers.Add("DSSubtopic", "bc"); } else { headers.Add("DSSubtopic", service + "-" + accountID); } headers.Remove("DSRequestTimeout"); body["clientId"] = service + "-" + accountID; int Id = Invoke(body); while (!results.ContainsKey(Id)) { await Task.Delay(10); } TypedObject result = GetResult(Id); // Read result and discard return(null); }
public static TypedObject MakeArrayCollection(object[] data) { TypedObject ret = new TypedObject("flex.messaging.io.ArrayCollection"); ret.Add("array", data); return(ret); }
public byte[] EncodeConnect(Dictionary <string, object> paramaters) { startTime = (long)DateTime.Now.TimeOfDay.TotalMilliseconds; List <Byte> result = new List <Byte>(); WriteStringAMF0(result, "connect"); WriteIntAMF0(result, 1); // invokeId // Write params result.Add((byte)0x11); // AMF3 object result.Add((byte)0x09); // Array WriteAssociativeArray(result, paramaters); // Write service call args result.Add((byte)0x01); result.Add((byte)0x00); // false WriteStringAMF0(result, "nil"); // "nil" WriteStringAMF0(result, ""); // "" // Set up CommandMessage TypedObject cm = new TypedObject("flex.messaging.messages.CommandMessage"); cm.Add("operation", 5); cm.Add("correlationId", ""); cm.Add("timestamp", 0); cm.Add("messageId", RandomUID()); cm.Add("body", new TypedObject(null)); cm.Add("destination", ""); Dictionary <string, object> headers = new Dictionary <string, object>(); headers.Add("DSMessagingVersion", 1.0); headers.Add("DSId", "my-rtmps"); cm.Add("headers", headers); cm.Add("clientId", null); cm.Add("timeToLive", 0); // Write CommandMessage result.Add((byte)0x11); // AMF3 object Encode(result, cm); byte[] ret = new byte[result.Count]; for (int i = 0; i < ret.Length; i++) { ret[i] = result[i]; } ret = AddHeaders(ret); ret[7] = (byte)0x14; // Change message type return(ret); }
protected TypedObject WrapBody(object body, string destination, object operation) { TypedObject headers = new TypedObject(); headers.Add("DSRequestTimeout", 60); headers.Add("DSId", DSId); headers.Add("DSEndpoint", "my-rtmps"); TypedObject ret = new TypedObject("flex.messaging.messages.RemotingMessage"); ret.Add("operation", operation); ret.Add("source", null); ret.Add("timestamp", 0); ret.Add("messageId", RTMPSEncoder.RandomUID()); ret.Add("timeToLive", 0); ret.Add("clientId", null); ret.Add("destination", destination); ret.Add("body", body); ret.Add("headers", headers); return ret; }
public async Task <object> Subscribe(SubsciptionService service, double accountId) { TypedObject body = WrapBody(new TypedObject(), "messagingDestination", 0); body.type = "flex.messaging.messages.CommandMessage"; TypedObject headers = body.GetTO("headers"); switch (service) { case SubsciptionService.GameService: headers.Add("DSSubtopic", "gn-" + accountID); body["clientId"] = "gn-" + accountID; break; case SubsciptionService.ClientService: headers.Add("DSSubtopic", "cn-" + accountID); body["clientId"] = "cn-" + accountID; break; case SubsciptionService.BroadcastService: headers.Add("DSSubtopic", "bc"); body["clientId"] = "bc-" + accountID; break; } headers.Remove("DSRequestTimeout"); int Id = Invoke(body); while (!results.ContainsKey(Id)) { await Task.Delay(10); } TypedObject result = GetResult(Id); // Read result and discard return(null); }
/// <summary> /// Reads the DSA. /// </summary> /// <returns></returns> private static TypedObject ReadDSA() { TypedObject ret = new TypedObject("DSA"); int flag; List <int> flags = ReadFlags(); for (int i = 0; i < flags.Count; i++) { flag = flags[i]; int bits = 0; if (i == 0) { if ((flag & 0x01) != 0) { ret.Add("body", Decode()); } if ((flag & 0x02) != 0) { ret.Add("clientId", Decode()); } if ((flag & 0x04) != 0) { ret.Add("destination", Decode()); } if ((flag & 0x08) != 0) { ret.Add("headers", Decode()); } if ((flag & 0x10) != 0) { ret.Add("messageId", Decode()); } if ((flag & 0x20) != 0) { ret.Add("timeStamp", Decode()); } if ((flag & 0x40) != 0) { ret.Add("timeToLive", Decode()); } bits = 7; } else if (i == 1) { if ((flag & 0x01) != 0) { ReadByte(); byte[] temp = ReadByteArray(); ret.Add("clientIdBytes", temp); ret.Add("clientId", ByteArrayToID(temp)); } if ((flag & 0x02) != 0) { ReadByte(); byte[] temp = ReadByteArray(); ret.Add("messageIdBytes", temp); ret.Add("messageId", ByteArrayToID(temp)); } bits = 2; } ReadRemaining(flag, bits); } flags = ReadFlags(); for (int i = 0; i < flags.Count; i++) { flag = flags[i]; int bits = 0; if (i == 0) { if ((flag & 0x01) != 0) { ret.Add("correlationId", Decode()); } if ((flag & 0x02) != 0) { ReadByte(); byte[] temp = ReadByteArray(); ret.Add("correlationIdBytes", temp); ret.Add("correlationId", ByteArrayToID(temp)); } bits = 2; } ReadRemaining(flag, bits); } return(ret); }
/// <summary> /// Reads the object. /// </summary> /// <returns></returns> /// <exception cref="System.NotImplementedException">Externalizable not handled for + cd.type</exception> private static object ReadObject() { int handle = ReadInt(); bool inline = ((handle & 1) != 0); handle = handle >> 1; if (inline) { bool inlineDefine = ((handle & 1) != 0); handle = handle >> 1; ClassDefinition cd; if (inlineDefine) { cd = new ClassDefinition(); cd.type = ReadString(); cd.externalizable = ((handle & 1) != 0); handle = handle >> 1; cd.dynamic = ((handle & 1) != 0); handle = handle >> 1; for (int i = 0; i < handle; i++) { cd.members.Add(ReadString()); } classDefinitions.Add(cd); } else { cd = classDefinitions[handle]; } TypedObject ret = new TypedObject(cd.type); // Need to add reference here due to circular references objectReferences.Add(ret); if (cd.externalizable) { if (cd.type.Equals("DSK")) { ret = ReadDSK(); } else if (cd.type.Equals("DSA")) { ret = ReadDSA(); } else if (cd.type.Equals("flex.messaging.io.ArrayCollection")) { object obj = Decode(); ret = TypedObject.MakeArrayCollection((object[])obj); } else if (cd.type.Equals("com.riotgames.platform.systemstate.ClientSystemStatesNotification") || cd.type.Equals("com.riotgames.platform.broadcast.BroadcastNotification")) { int size = 0; for (int i = 0; i < 4; i++) { size = size * 256 + ReadByteAsInt(); } byte[] data = ReadBytes(size); StringBuilder sb = new StringBuilder(); for (int i = 0; i < data.Length; i++) { sb.Append(Convert.ToChar(data[i])); } JavaScriptSerializer serializer = new JavaScriptSerializer(); ret = serializer.Deserialize <TypedObject>(sb.ToString()); ret.type = cd.type; } else { //for (int i = dataPos; i < dataBuffer.length; i++) //System.out.print(String.format("%02X", dataBuffer[i])); //System.out.println(); throw new NotImplementedException("Externalizable not handled for " + cd.type); } } else { for (int i = 0; i < cd.members.Count; i++) { String key = cd.members[i]; object value = Decode(); ret.Add(key, value); } if (cd.dynamic) { String key; while ((key = ReadString()).Length != 0) { object value = Decode(); ret.Add(key, value); } } } return(ret); } else { return(objectReferences[handle]); } }
private bool Login() { TypedObject result, body; // Login 1 body = new TypedObject("com.riotgames.platform.login.AuthenticationCredentials"); body.Add("clientVersion", clientVersion); body.Add("ipAddress", ipAddress); body.Add("securityAnswer", null); body.Add("locale", locale); body.Add("domain", "lolclient.lol.riotgames.com"); body.Add("oldPassword", null); body.Add("authToken", authToken); if (useGarena) { body.Add("partnerCredentials", "8393 " + garenaToken); body.Add("username", userID); body.Add("password", null); } else { body.Add("partnerCredentials", null); body.Add("username", user); body.Add("password", password); } int id = Invoke("loginService", "login", new object[] { body }); result = GetResult(id); if (result["result"].Equals("_error")) { Error(GetErrorMessage(result), ErrorType.Login); Disconnect(); return(false); } body = result.GetTO("data").GetTO("body"); sessionToken = body.GetString("token"); accountID = (int)body.GetTO("accountSummary").GetInt("accountId"); // Login 2 if (useGarena) { body = WrapBody(Convert.ToBase64String(Encoding.UTF8.GetBytes(userID + ":" + sessionToken)), "auth", 8); } else { body = WrapBody(Convert.ToBase64String(Encoding.UTF8.GetBytes(user.ToLower() + ":" + sessionToken)), "auth", 8); } body.type = "flex.messaging.messages.CommandMessage"; id = Invoke(body); result = GetResult(id); // Read result (and discard) isLoggedIn = true; if (OnLogin != null) { OnLogin(this, user, ipAddress); } return(true); }