public TypedObject DecodeConnect(byte[] data) { this.Reset(); this.dataBuffer = data; this.dataPos = 0; TypedObject obj2 = new TypedObject("Invoke"); obj2.Add("result", this.DecodeAMF0()); obj2.Add("invokeId", this.DecodeAMF0()); obj2.Add("serviceCall", this.DecodeAMF0()); obj2.Add("data", this.DecodeAMF0()); if (this.dataPos != this.dataBuffer.Length) { for (int i = this.dataPos; i < data.Length; i++) { if (this.ReadByte() != 0) { throw new Exception("There is other data in the buffer!"); } } } if (this.dataPos != this.dataBuffer.Length) { object[] objArray1 = new object[] { "Did not consume entire buffer: ", this.dataPos, " of ", this.dataBuffer.Length }; throw new Exception(string.Concat(objArray1)); } return(obj2); }
public 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); }
private 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); }
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); } return(result); }
private TypedObject ReadObjectAMF0() { string str; TypedObject obj2 = new TypedObject("Body"); while (!(str = this.ReadStringAMF0()).Equals("")) { byte num = this.ReadByte(); switch (num) { case 0: { obj2.Add(str, this.ReadDouble()); continue; } case 2: { obj2.Add(str, this.ReadStringAMF0()); continue; } } if (num != 5) { throw new NotImplementedException("AMF0 type not supported: " + num); } obj2.Add(str, null); } this.ReadByte(); return(obj2); }
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 TypedObject DecodeInvoke(byte[] data) { this.Reset(); this.dataBuffer = data; this.dataPos = 0; TypedObject typedObject = new TypedObject("Invoke"); if (this.dataBuffer[0] == 0) { this.dataPos++; typedObject.Add("version", 0); } typedObject.Add("result", this.DecodeAMF0()); typedObject.Add("invokeId", this.DecodeAMF0()); typedObject.Add("serviceCall", this.DecodeAMF0()); typedObject.Add("data", this.DecodeAMF0()); if (this.dataPos != this.dataBuffer.Length) { throw new Exception(string.Concat(new object[] { "Did not consume entire buffer: ", this.dataPos, " of ", this.dataBuffer.Length })); } return(typedObject); }
private TypedObject ReadObjectAMF0() { TypedObject typedObject = new TypedObject("Body"); string key; while (!(key = this.ReadStringAMF0()).Equals("")) { byte b = this.ReadByte(); if (b == 0) { typedObject.Add(key, this.ReadDouble()); } else if (b == 2) { typedObject.Add(key, this.ReadStringAMF0()); } else { if (b != 5) { throw new NotImplementedException("AMF0 type not supported: " + b); } typedObject.Add(key, null); } } this.ReadByte(); return(typedObject); }
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) { 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 byte[] EncodeConnect(Dictionary <string, object> paramaters) { List <byte> list = new List <byte>(); this.WriteStringAMF0(list, "connect"); this.WriteIntAMF0(list, 1); list.Add(17); list.Add(9); this.WriteAssociativeArray(list, paramaters); list.Add(1); list.Add(0); this.WriteStringAMF0(list, "nil"); this.WriteStringAMF0(list, ""); TypedObject typedObject = new TypedObject("flex.messaging.messages.CommandMessage"); typedObject.Add("operation", 5); typedObject.Add("correlationId", ""); typedObject.Add("timestamp", 0); typedObject.Add("messageId", RTMPSEncoder.RandomUID()); typedObject.Add("body", new TypedObject(null)); typedObject.Add("destination", ""); typedObject.Add("headers", new Dictionary <string, object> { { "DSMessagingVersion", 1.0 }, { "DSId", "my-rtmps" } }); typedObject.Add("clientId", null); typedObject.Add("timeToLive", 0); list.Add(17); this.Encode(list, typedObject); byte[] array = new byte[list.Count]; for (int i = 0; i < array.Length; i++) { array[i] = list[i]; } array = this.AddHeaders(array); array[7] = 20; return(array); }
public byte[] EncodeConnect(Dictionary <string, object> paramaters) { List <byte> ret = new List <byte>(); this.WriteStringAMF0(ret, "connect"); this.WriteIntAMF0(ret, 1); ret.Add(0x11); ret.Add(9); this.WriteAssociativeArray(ret, paramaters); ret.Add(1); ret.Add(0); this.WriteStringAMF0(ret, "nil"); this.WriteStringAMF0(ret, ""); TypedObject obj2 = new TypedObject("flex.messaging.messages.CommandMessage"); obj2.Add("operation", 5); obj2.Add("correlationId", ""); obj2.Add("timestamp", 0); obj2.Add("messageId", RandomUID()); obj2.Add("body", new TypedObject(null)); obj2.Add("destination", ""); Dictionary <string, object> dictionary = new Dictionary <string, object>(); dictionary.Add("DSMessagingVersion", 1.0); dictionary.Add("DSId", "my-rtmps"); obj2.Add("headers", dictionary); obj2.Add("clientId", null); obj2.Add("timeToLive", 0); ret.Add(0x11); this.Encode(ret, obj2); byte[] data = new byte[ret.Count]; for (int i = 0; i < data.Length; i++) { data[i] = ret[i]; } data = this.AddHeaders(data); data[7] = 20; return(data); }
public async Task <SearchingForMatchNotification> AttachToLowPriorityQueue(MatchMakerParams matchMakerParams, string accessToken) { TypedObject to = new TypedObject(null); to.Add("LEAVER_BUSTER_ACCESS_TOKEN", accessToken); int Id = Invoke("matchmakerService", "attachToQueue", new object[] { matchMakerParams.GetBaseTypedObject(), to }); while (!results.ContainsKey(Id)) { await Task.Delay(10); } TypedObject messageBody = results[Id].GetTO("data").GetTO("body"); SearchingForMatchNotification result = new SearchingForMatchNotification(messageBody); results.Remove(Id); return(result); }
public async Task <SearchingForMatchNotification> AttachToLowPriorityQueue(MatchMakerParams matchMakerParams, string accessToken) { TypedObject typedObject = new TypedObject(null); typedObject.Add("LEAVER_BUSTER_ACCESS_TOKEN", accessToken); int key = this.Invoke("matchmakerService", "attachToQueue", new object[] { matchMakerParams.GetBaseTypedObject(), typedObject }); while (!this.results.ContainsKey(key)) { await Task.Delay(10); } TypedObject tO = this.results[key].GetTO("data").GetTO("body"); SearchingForMatchNotification result = new SearchingForMatchNotification(tO); this.results.Remove(key); return(result); }
private 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 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); }
private TypedObject ReadDSA() { int num; TypedObject obj2 = new TypedObject("DSA"); List <int> list = this.ReadFlags(); for (int i = 0; i < list.Count; i++) { num = list[i]; int bits = 0; switch (i) { case 0: if ((num & 1) != 0) { obj2.Add("body", this.Decode()); } if ((num & 2) != 0) { obj2.Add("clientId", this.Decode()); } if ((num & 4) != 0) { obj2.Add("destination", this.Decode()); } if ((num & 8) != 0) { obj2.Add("headers", this.Decode()); } if ((num & 0x10) != 0) { obj2.Add("messageId", this.Decode()); } if ((num & 0x20) != 0) { obj2.Add("timeStamp", this.Decode()); } if ((num & 0x40) != 0) { obj2.Add("timeToLive", this.Decode()); } bits = 7; break; case 1: if ((num & 1) != 0) { this.ReadByte(); byte[] buffer = this.ReadByteArray(); obj2.Add("clientIdBytes", buffer); obj2.Add("clientId", this.ByteArrayToID(buffer)); } if ((num & 2) != 0) { this.ReadByte(); byte[] buffer2 = this.ReadByteArray(); obj2.Add("messageIdBytes", buffer2); obj2.Add("messageId", this.ByteArrayToID(buffer2)); } bits = 2; break; } this.ReadRemaining(num, bits); } list = this.ReadFlags(); for (int j = 0; j < list.Count; j++) { num = list[j]; int num5 = 0; if (j == 0) { if ((num & 1) != 0) { obj2.Add("correlationId", this.Decode()); } if ((num & 2) != 0) { this.ReadByte(); byte[] buffer3 = this.ReadByteArray(); obj2.Add("correlationIdBytes", buffer3); obj2.Add("correlationId", this.ByteArrayToID(buffer3)); } num5 = 2; } this.ReadRemaining(num, num5); } return(obj2); }
private object ReadObject() { int num = this.ReadInt(); bool flag = (num & 1) != 0; num >>= 1; if (flag) { bool flag2 = (num & 1) != 0; num >>= 1; ClassDefinition classDefinition; if (flag2) { classDefinition = new ClassDefinition(); classDefinition.type = this.ReadString(); classDefinition.externalizable = ((num & 1) != 0); num >>= 1; classDefinition.dynamic = ((num & 1) != 0); num >>= 1; for (int i = 0; i < num; i++) { classDefinition.members.Add(this.ReadString()); } this.classDefinitions.Add(classDefinition); } else { classDefinition = this.classDefinitions[num]; } TypedObject typedObject = new TypedObject(classDefinition.type); this.objectReferences.Add(typedObject); if (classDefinition.externalizable) { if (classDefinition.type.Equals("DSK")) { typedObject = this.ReadDSK(); } else if (classDefinition.type.Equals("DSA")) { typedObject = this.ReadDSA(); } else if (classDefinition.type.Equals("flex.messaging.io.ArrayCollection")) { object obj = this.Decode(); typedObject = TypedObject.MakeArrayCollection((object[])obj); } else { if (!classDefinition.type.Equals("com.riotgames.platform.systemstate.ClientSystemStatesNotification") && !classDefinition.type.Equals("com.riotgames.platform.broadcast.BroadcastNotification")) { throw new NotImplementedException("Externalizable not handled for " + classDefinition.type); } int num2 = 0; for (int j = 0; j < 4; j++) { num2 = num2 * 256 + this.ReadByteAsInt(); } byte[] array = this.ReadBytes(num2); StringBuilder stringBuilder = new StringBuilder(); for (int k = 0; k < array.Length; k++) { stringBuilder.Append(Convert.ToChar(array[k])); } JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); typedObject = javaScriptSerializer.Deserialize <TypedObject>(stringBuilder.ToString()); typedObject.type = classDefinition.type; } } else { for (int l = 0; l < classDefinition.members.Count; l++) { string key = classDefinition.members[l]; object value = this.Decode(); typedObject.Add(key, value); } if (classDefinition.dynamic) { string key2; while ((key2 = this.ReadString()).Length != 0) { object value2 = this.Decode(); typedObject.Add(key2, value2); } } } return(typedObject); } return(this.objectReferences[num]); }
private TypedObject ReadDSA() { TypedObject typedObject = new TypedObject("DSA"); List <int> list = this.ReadFlags(); for (int i = 0; i < list.Count; i++) { int num = list[i]; int bits = 0; if (i == 0) { if ((num & 1) != 0) { typedObject.Add("body", this.Decode()); } if ((num & 2) != 0) { typedObject.Add("clientId", this.Decode()); } if ((num & 4) != 0) { typedObject.Add("destination", this.Decode()); } if ((num & 8) != 0) { typedObject.Add("headers", this.Decode()); } if ((num & 16) != 0) { typedObject.Add("messageId", this.Decode()); } if ((num & 32) != 0) { typedObject.Add("timeStamp", this.Decode()); } if ((num & 64) != 0) { typedObject.Add("timeToLive", this.Decode()); } bits = 7; } else if (i == 1) { if ((num & 1) != 0) { this.ReadByte(); byte[] array = this.ReadByteArray(); typedObject.Add("clientIdBytes", array); typedObject.Add("clientId", this.ByteArrayToID(array)); } if ((num & 2) != 0) { this.ReadByte(); byte[] array2 = this.ReadByteArray(); typedObject.Add("messageIdBytes", array2); typedObject.Add("messageId", this.ByteArrayToID(array2)); } bits = 2; } this.ReadRemaining(num, bits); } list = this.ReadFlags(); for (int j = 0; j < list.Count; j++) { int num = list[j]; int bits2 = 0; if (j == 0) { if ((num & 1) != 0) { typedObject.Add("correlationId", this.Decode()); } if ((num & 2) != 0) { this.ReadByte(); byte[] array3 = this.ReadByteArray(); typedObject.Add("correlationIdBytes", array3); typedObject.Add("correlationId", this.ByteArrayToID(array3)); } bits2 = 2; } this.ReadRemaining(num, bits2); } return(typedObject); }