public static V6Packet BuildConnectionPacket(MIMCUser user) { logger.DebugFormat("{0} User BuildConnectionPacket", user.AppAccount); V6Packet v6Packet = new V6Packet(); V6Body v6Body = new V6Body(); XMMsgConn xMMsgConn = new XMMsgConn(); xMMsgConn.os = "macOS"; xMMsgConn.udid = user.Connection.Udid; xMMsgConn.version = Constant.CONN_BIN_PROTO_VERSION; ClientHeader clientHeader = MIMCUtil.CreateClientHeader(user, Constant.CMD_CONN, Constant.CIPHER_NONE, MIMCUtil.CreateMsgId(user)); v6Body.PayloadType = Constant.PAYLOAD_TYPE; v6Body.ClientHeader = clientHeader; using (MemoryStream ms = new MemoryStream()) { Serializer.Serialize(ms, xMMsgConn); byte[] payload = ms.ToArray(); v6Body.Payload = payload; v6Packet.Body = v6Body; } return(v6Packet); }
public static V6Packet BuildUnBindPacket(MIMCUser user) { logger.DebugFormat("{0} User BuildUnBindPacket", user.AppAccount); ClientHeader clientHeader = MIMCUtil.CreateClientHeader(user, Constant.CMD_UNBIND, Constant.CIPHER_NONE, MIMCUtil.CreateMsgId(user)); V6Packet v6Packet = new V6Packet(); V6Body v6Body = new V6Body(); v6Body.PayloadType = Constant.PAYLOAD_TYPE; v6Body.ClientHeader = clientHeader; v6Packet.Body = v6Body; return(v6Packet); }
public static V6Packet BuildSecMsgPacket(MIMCUser user, string packetId, byte[] packetBin) { logger.DebugFormat("{0} User BuildSecMsgPacket", user.AppAccount); ClientHeader clientHeader = MIMCUtil.CreateClientHeader(user, Constant.CMD_SECMSG, Constant.CIPHER_RC4, packetId); V6Packet v6Packet = new V6Packet(); V6Body v6Body = new V6Body(); v6Body.PayloadType = Constant.PAYLOAD_TYPE; v6Body.ClientHeader = clientHeader; v6Body.Payload = packetBin; v6Packet.Body = v6Body; return(v6Packet); }
public static V6Packet BuildBindPacket(MIMCUser user) { if (string.IsNullOrEmpty(user.Token)) { logger.DebugFormat("{0} User BuildBindPacket fail Token is null,wait ...", user.AppAccount); return(null); } logger.DebugFormat("{0} User BuildBindPacket", user.AppAccount); ClientHeader clientHeader = MIMCUtil.CreateClientHeader(user, Constant.CMD_BIND, Constant.CIPHER_NONE, MIMCUtil.CreateMsgId(user)); XMMsgBind xMMsgBind = new XMMsgBind(); xMMsgBind.token = user.Token; xMMsgBind.method = Constant.METHOD; xMMsgBind.client_attrs = user.ClientAttrs; xMMsgBind.cloud_attrs = user.CloudAttrs; xMMsgBind.kick = Constant.NO_KICK; string sign = MIMCUtil.GenerateSig(clientHeader, xMMsgBind, user.Connection.Challenge, user.SecurityKey); if (String.IsNullOrEmpty(sign)) { logger.WarnFormat("GenerateSig fail sign is null"); return(null); } xMMsgBind.sig = sign; V6Packet v6Packet = new V6Packet(); V6Body v6Body = new V6Body(); v6Body.PayloadType = Constant.PAYLOAD_TYPE; v6Body.ClientHeader = clientHeader; using (MemoryStream ms = new MemoryStream()) { Serializer.Serialize(ms, xMMsgBind); byte[] payload = ms.ToArray(); v6Body.Payload = payload; v6Packet.Body = v6Body; } return(v6Packet); }
public static V6Packet BuildSequenceAckPacket(MIMCUser user, MIMCPacketList packetList) { logger.DebugFormat("{0} User BuildSequenceAckPacket", user.AppAccount); MIMCPacket packet = new MIMCPacket(); packet.packetId = MIMCUtil.CreateMsgId(user); packet.package = user.AppPackage; packet.type = MIMC_MSG_TYPE.SEQUENCE_ACK; MIMCSequenceAck sequenceAck = new MIMCSequenceAck(); sequenceAck.uuid = packetList.uuid; sequenceAck.resource = packetList.resource; sequenceAck.sequence = packetList.maxSequence; using (MemoryStream ms = new MemoryStream()) { Serializer.Serialize(ms, sequenceAck); byte[] sequenceAckBin = ms.ToArray(); packet.payload = sequenceAckBin; } byte[] mimcBins = null; using (MemoryStream mimcStream = new MemoryStream()) { Serializer.Serialize(mimcStream, packet); mimcBins = mimcStream.ToArray(); } ClientHeader clientHeader = MIMCUtil.CreateClientHeader(user, Constant.CMD_SECMSG, Constant.CIPHER_RC4, packet.packetId); V6Packet v6Packet = new V6Packet(); V6Body v6Body = new V6Body(); v6Body.PayloadType = Constant.PAYLOAD_TYPE; v6Body.ClientHeader = clientHeader; v6Body.Payload = mimcBins; v6Packet.Body = v6Body; return(v6Packet); }
public static string CreateMsgId(MIMCUser user) { return(MIMCUtil.GetRandomString(15, true, true, false, false, null) + "-" + user.Atomic.IncrementAndGet()); }