Beispiel #1
0
        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);
        }
Beispiel #2
0
        public IActionResult Post([FromBody] ClientDet clientDet)
        {
            try
            {
                if (clientDet.Id == Guid.Empty)
                {
                    ClientHeader clientHeader = _unitOfWork.ClientHeaders.SingleOrDefault(c => c.Id == clientDet.ClientHeaderId, true);

                    if (clientHeader.Id != Guid.Empty)
                    {
                        //var userId = User.FindFirstValue("sub");

                        var clientDetail = _mapper.Map <ClientDetail>(clientDet);

                        _unitOfWork.ClientDetails.Add(clientDetail);

                        _unitOfWork.Complete();

                        return(Created(new Uri($"{Request.Path}/{clientDetail.Id}", UriKind.Relative), _mapper.Map <ClientDet>(clientDetail)));
                    }
                }
            }
            catch (Exception e)
            {
                string message = e.Message;
            }

            return(BadRequest());
        }
Beispiel #3
0
 public static object[] Unpack(ClientHeader sourceArray)
 {
     object[] clientHeader = new object[3];
     clientHeader[0] = sourceArray.Length;
     clientHeader[1] = sourceArray.MessageID;
     clientHeader[2] = sourceArray.SN;
     return(clientHeader);
 }
Beispiel #4
0
    public static void Send_Heart()
    {
        byte[]       res    = Encoding.ASCII.GetBytes("");
        ClientHeader header = new ClientHeader();

        header = GetHeader(MessageID.CMD_HEART_BEAT_RSP, 0);
        connector.SendMsg(header, res);
    }
Beispiel #5
0
    public static ClientHeader UnPackObject(byte[] bs)
    {
        ClientHeader header = new ClientHeader();

        header.Length    = BitConverter.ToUInt32(bs, 0);
        header.Flag      = BitConverter.ToUInt32(bs, 4);
        header.MessageID = BitConverter.ToUInt32(bs, 8);
        header.ProtoType = BitConverter.ToUInt32(bs, 12);
        return(header);
    }
Beispiel #6
0
    void start_recv_data()
    {
        if (this.is_Connect == false)
        {
            return;
        }

        while (true)
        {
            if (!this.client.Connected)
            {
                break;
            }

            try
            {
                Debug.Log("读取数据中...");
                int recv_len = 0;
                // small
                if (this.receved < RECV_LEN)
                {
                    recv_len = this.client.Receive(this.recv_buffer, this.receved, RECV_LEN - this.receved,
                                                   SocketFlags.None);
                }
                else
                {
                    if (this.long_pkg == null)
                    {
                        var out_header = new byte[PackTools.PACK_LENGTH];
                        Array.Copy(this.recv_buffer, out_header, out_header.Length);
                        ClientHeader header = PackTools.UnPackObject(out_header);
                        this.long_pkg_size = Convert.ToInt32(header.Length);
                        this.long_pkg      = new byte[header.Length];
                        //将上次的数据拷贝到这次的大包数组里
                        Array.Copy(this.recv_buffer, 0, this.long_pkg, 0, this.receved);
                    }

                    recv_len = this.client.Receive(this.recv_buffer, this.receved, RECV_LEN - this.receved,
                                                   SocketFlags.None);
                }

                if (recv_len > 0)
                {
                    this.receved += recv_len;
                    tcp_Func();
                }
            }
            catch (Exception e)
            {
                Debug.Log(e.Message);
                EventManager.Instance.Call("EVENT.NET.CLOSE", null);
                break;
            }
        }
    }
        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);
        }
Beispiel #8
0
        public static void Test(LuaTable tb)
        {
            ClientHeader clientHeader = new ClientHeader()
            {
                Length = 12, MessageID = 101, SN = 2
            };

            using (MemoryStream stream = new MemoryStream())
            {
                amf.Encode(stream, clientHeader);
                Debug.Log(stream.ToArray());
                Utils.utils.Log("Encode:", stream.ToArray());
            }
        }
Beispiel #9
0
        ClientHeader ConvertHeader(byte[] headerBuffer)
        {
            ClientHeader header = new ClientHeader();

            //
            byte[] lengthBytes = Client.CopyArray(headerBuffer, 0, 4);

            header.Length = BitConverter.ToUInt32(lengthBytes, 0);
            byte[] messageBytes = Client.CopyArray(headerBuffer, 4, 8);;
            header.MessageID = BitConverter.ToUInt32(messageBytes, 0);
            byte[] snBytes = Client.CopyArray(headerBuffer, 8, 12);
            header.SN = BitConverter.ToUInt32(snBytes, 0);
            return(header);
        }
Beispiel #10
0
        public static ClientHeader CreateClientHeader(MIMCUser user, String cmd, int cipher, String msgId)
        {
            logger.DebugFormat("{0} CreateClientHeader cmd:{1},msgId:{2}", user.AppAccount, cmd, msgId);
            ClientHeader clientHeader = new ClientHeader();

            clientHeader.id       = msgId;
            clientHeader.uuid     = (long)user.Uuid;
            clientHeader.chid     = Constant.MIMC_CHID;
            clientHeader.resource = user.Resource;
            clientHeader.cmd      = cmd;
            clientHeader.server   = Constant.SERVER;
            clientHeader.cipher   = cipher;
            clientHeader.dir_flag = ClientHeader.MSG_DIR_FLAG.CS_REQ;
            return(clientHeader);
        }
Beispiel #11
0
        /// <summary>
        /// 转换头部
        /// </summary>
        /// <returns></returns>
        byte[] ConvertNetHeader(ClientHeader header)
        {
            List <byte> buffer = new List <byte>();
            Type        tp     = header.GetType();

            System.Reflection.FieldInfo[] infos = tp.GetFields();
            object[] obs = new object[infos.Length];
            for (int i = 0; i < infos.Length; i += 1)
            {
                //
                obs[i] = infos[i].GetValue(header as object);
                var bs = BitConverter.GetBytes((uint)obs[i]);
                buffer.AddRange(bs);
            }
            return(buffer.ToArray());
        }
Beispiel #12
0
        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);
        }
Beispiel #13
0
    public void Send_EnterRoom()
    {
        enter xmsg = new enter();

        xmsg.m_nRoomID = 0;
        byte[] msgBytes;
        using (MemoryStream stream = new MemoryStream())
        {
            ProtoBuf.Serializer.Serialize(stream, xmsg);
            msgBytes = stream.ToArray();
        }

        ClientHeader header = new ClientHeader();

        header = GetHeader(MessageID.CMD_ENTERROOM, msgBytes.Length);

        connector.SendMsg(header, msgBytes);
    }
Beispiel #14
0
    public static void Send_Find_Friend(string name)
    {
        Friend_getInfo xmsg = new Friend_getInfo();

        xmsg.m_NameOther = name;

        byte[] msgBytes;
        using (MemoryStream stream = new MemoryStream())
        {
            ProtoBuf.Serializer.Serialize(stream, xmsg);
            msgBytes = stream.ToArray();
        }

        ClientHeader header = new ClientHeader();

        header = GetHeader(MessageID.MSG_FRIEND_GETINFO, msgBytes.Length);
        connector.SendMsg(header, msgBytes);
    }
Beispiel #15
0
    public void start_send_data(ClientHeader header, byte[] body)
    {
        if (this.is_Connect == false)
        {
            return;
        }

        if (!this.client.Connected)
        {
            return;
        }

        var         data   = PackTools.PackObject(header);
        List <byte> buffer = new List <byte>(data);

        buffer.AddRange(body);
        this.sendQueue.Enqueue(buffer.ToArray());
    }
Beispiel #16
0
        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);
        }
Beispiel #17
0
    public static void Send_GameChoose(int num) //服务器 -x:选择x   客户端 100+x  选择x
    {
        OnGameChoose xmsg = new OnGameChoose();

        //xmsg.m_iTankID = UnityEngine.Random.Range(1, 5);
        //xmsg.m_iTankID = xmsg.m_iTankID * 100000 + 1;
        if (num > 100)
        {
            num = -(num - 100);
        }
        xmsg.m_iTankID = num;
        xmsg.m_iSkill1 = Network.skill1;
        xmsg.m_iSkill2 = Network.skill2;

        byte[] msgBytes;
        using (MemoryStream stream = new MemoryStream())
        {
            ProtoBuf.Serializer.Serialize(stream, xmsg);
            msgBytes = stream.ToArray();
        }


        OnGame ongame = new OnGame();

        ongame.gameData       = msgBytes;
        ongame.m_iRoomID      = Network.Myplayer.m_iRoomID;
        ongame.m_iTableID     = Network.gameInfo_sitdown.m_iTableID;
        ongame.m_icmd         = (int)GameID.Choose;
        ongame.gameDataLength = msgBytes.Length;

        byte[] res;
        using (MemoryStream stream = new MemoryStream())
        {
            ProtoBuf.Serializer.Serialize(stream, ongame);
            res = stream.ToArray();
        }

        ClientHeader header = new ClientHeader();

        header = GetHeader(MessageID.CMD_PLAYGAME, res.Length);

        connector.SendMsg(header, res);
    }
Beispiel #18
0
        internal static string GenerateSig(ClientHeader header, XMMsgBind bind, string challenge, string securityKey)
        {
            Hashtable paramsMap = new Hashtable();

            paramsMap.Add("challenge", challenge);
            paramsMap.Add("token", bind.token);
            paramsMap.Add("chid", header.chid);
            paramsMap.Add("from", String.Format("{0}@xiaomi.com/{1}", header.uuid, header.resource));
            paramsMap.Add("id", header.id);
            paramsMap.Add("to", Constant.SERVER);
            paramsMap.Add("kick", bind.kick);
            paramsMap.Add("client_attrs", bind.client_attrs == null ? "" : bind.client_attrs);
            paramsMap.Add("cloud_attrs", bind.cloud_attrs == null ? "" : bind.cloud_attrs);

            ArrayList exps = new ArrayList();

            exps.Add(bind.method.ToUpper());
            ArrayList lst = new ArrayList(paramsMap.Keys);

            lst.Sort();
            foreach (string key in lst)
            {
                exps.Add(String.Format("{0}={1}", key, paramsMap[key]));
            }

            exps.Add(securityKey);
            //logger.DebugFormat("GenerateSig =======securityKey:{0}", securityKey);

            bool          first = true;
            StringBuilder sb    = new StringBuilder();

            foreach (String s in exps)
            {
                if (!first)
                {
                    sb.Append('&');
                }
                sb.Append(s);
                first = false;
            }
            //logger.DebugFormat(sb.ToString());
            return(Hash4SHA1(sb.ToString()));
        }
Beispiel #19
0
    public static void Send_Invitation_Notify_Friend(bool accepted)
    {
        Friend_resInvNotify xmsg = new Friend_resInvNotify();

        xmsg.m_iOptID1 = Network.playerid;
        xmsg.m_iOptID2 = Network.Invitation_id;
        xmsg.accept    = accepted;

        byte[] msgBytes;
        using (MemoryStream stream = new MemoryStream())
        {
            ProtoBuf.Serializer.Serialize(stream, xmsg);
            msgBytes = stream.ToArray();
        }

        ClientHeader header = new ClientHeader();

        header = GetHeader(MessageID.MSG_FRIEND_OPT_INV, msgBytes.Length);
        connector.SendMsg(header, msgBytes);
    }
Beispiel #20
0
    public static void Send_Add_Notify_Friend(string name1, string name2, bool accepted)
    {
        Friend_resAddNotify xmsg = new Friend_resAddNotify();

        xmsg.Name1  = name1;
        xmsg.Name2  = name2;
        xmsg.accept = accepted;

        byte[] msgBytes;
        using (MemoryStream stream = new MemoryStream())
        {
            ProtoBuf.Serializer.Serialize(stream, xmsg);
            msgBytes = stream.ToArray();
        }

        ClientHeader header = new ClientHeader();

        header = GetHeader(MessageID.MSG_FRIEND_OPT_ADD, msgBytes.Length);
        connector.SendMsg(header, msgBytes);
    }
Beispiel #21
0
    public static void Send_PVE_Over(bool status)
    {
        PVE_over xmsg = new PVE_over();

        xmsg.m_iWin = status;

        byte[] msgBytes;
        using (MemoryStream stream = new MemoryStream())
        {
            ProtoBuf.Serializer.Serialize(stream, xmsg);
            msgBytes = stream.ToArray();
        }

        ClientHeader header = new ClientHeader();

        header = GetHeader(MessageID.MSG_PVE_OVER, msgBytes.Length);

        CMD_MAP_MATCH_result = -1;
        connector.SendMsg(header, msgBytes);
    }
Beispiel #22
0
    public void sendNetData()
    {
        var obj = new object[]
        {
            sn += 1,
            InputFields[0].text,
            InputFields[1].text
        };
        var buffer = NetPackData.pack_all(obj);

        var header = new ClientHeader()
        {
            Length    = Convert.ToUInt32(PackTools.PACK_LENGTH) + Convert.ToUInt32(buffer.Length),
            Flag      = 2,
            MessageID = 101,
            ProtoType = 1,
        };

        network.instance.start_send_data(header, buffer);
    }
Beispiel #23
0
        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);
        }
Beispiel #24
0
    public static void Send_Invitation_Friend(string name)
    {
        Network.gamemode = BattleType.NORMAL_PVP;
        Network.Init();
        Friend_invitation xmsg = new Friend_invitation();

        xmsg.m_NameOther  = name;
        xmsg.m_iOptIDself = Network.playerid;

        byte[] msgBytes;
        using (MemoryStream stream = new MemoryStream())
        {
            ProtoBuf.Serializer.Serialize(stream, xmsg);
            msgBytes = stream.ToArray();
        }

        ClientHeader header = new ClientHeader();

        header = GetHeader(MessageID.MSG_FRIEND_INVITATION, msgBytes.Length);
        connector.SendMsg(header, msgBytes);
    }
Beispiel #25
0
    // Start is called before the first frame update
    void Start()
    {
//        var obj = new object[]
//        {
//            new char[]
//            {
//                'a',
//                '增',
//                '怕',
//                '%'
//            },
//        };
        LogTool.Instance.ToStringAll(BitConverter.GetBytes((Int16)(50)));
        ClientHeader header = new ClientHeader();

        SerializableStructAttribute[] objects =
            (SerializableStructAttribute[])header.GetType()
            .GetCustomAttributes(typeof(SerializableStructAttribute), false);

        foreach (var VARIABLE in objects)
        {
            Debug.Log(VARIABLE);
        }
        EventManager.Instance.AddEventAction("EVENT.NET.MESSAGE", (msg) =>
        {
            SMessage m = msg as SMessage;
            print(m.Header.MessageID);
            EventManager.Instance.Call($"EVENT.NET.MESSAGE.{m.Header.MessageID}", 1.5);
        });
//
//        var bs = NetPackData.pack_all(obj);
////
////        LogTool.Instance.ToStringAll((byte)('a'));
////        LogTool.Instance.ToStringAll(BitConverter.GetBytes(false));
////        LogTool.Instance.ToStringAll(bs);
//
//        var obj_oo = NetUnPackData.unpack_all(bs);
//        LogTool.Instance.ToStringAll(obj_oo);
//        .Instance.LogBytes(bs);
    }
Beispiel #26
0
    public static void Send_Del_Friend(string name)
    {
        if (Add_Friend_List.ContainsKey(name))
        {
            Add_Friend_List.Remove(name);
        }
        Friend_add_del xmsg = new Friend_add_del();

        xmsg.m_NameOther = name;

        byte[] msgBytes;
        using (MemoryStream stream = new MemoryStream())
        {
            ProtoBuf.Serializer.Serialize(stream, xmsg);
            msgBytes = stream.ToArray();
        }

        ClientHeader header = new ClientHeader();

        header = GetHeader(MessageID.MSG_FRIEND_DEL, msgBytes.Length);
        connector.SendMsg(header, msgBytes);
    }
Beispiel #27
0
    public static void Send_Quit()
    {
        OnGame ongame = new OnGame();

        ongame.gameData       = Encoding.ASCII.GetBytes("x");
        ongame.m_iRoomID      = Network.Myplayer.m_iRoomID;
        ongame.m_iTableID     = Network.gameInfo_sitdown.m_iTableID;
        ongame.m_icmd         = (int)GameID.Quit;
        ongame.gameDataLength = 1;

        byte[] res;
        using (MemoryStream stream = new MemoryStream())
        {
            ProtoBuf.Serializer.Serialize(stream, ongame);
            res = stream.ToArray();
        }

        ClientHeader header = new ClientHeader();

        header = GetHeader(MessageID.CMD_PLAYGAME, res.Length);
        connector.SendMsg(header, res);
    }
Beispiel #28
0
    public static void Send_Move(bool keydown, int direction, float time, float x, float y)
    {
        OnGameMove xmsg = new OnGameMove();

        xmsg.m_iKeyDown      = keydown;
        xmsg.m_iDirection    = direction;
        xmsg.m_iIntervalTime = time;

        xmsg.m_iPosX  = x;
        xmsg.m_iPosY  = y;
        xmsg.m_iOptID = Network.playerid;

        byte[] msgBytes;
        using (MemoryStream stream = new MemoryStream())
        {
            ProtoBuf.Serializer.Serialize(stream, xmsg);
            msgBytes = stream.ToArray();
        }

        OnGame ongame = new OnGame();

        ongame.gameData       = msgBytes;
        ongame.m_iRoomID      = Network.Myplayer.m_iRoomID;
        ongame.m_iTableID     = Network.gameInfo_sitdown.m_iTableID;
        ongame.m_icmd         = (int)GameID.Move;
        ongame.gameDataLength = msgBytes.Length;

        byte[] res;
        using (MemoryStream stream = new MemoryStream())
        {
            ProtoBuf.Serializer.Serialize(stream, ongame);
            res = stream.ToArray();
        }

        ClientHeader header = new ClientHeader();

        header = GetHeader(MessageID.CMD_PLAYGAME, res.Length);
        connector.SendMsg(header, res);
    }
        private void ComboMessageType_SelectedIndexChanged(object sender, EventArgs e)
        {
            var index = ComboMessageType.SelectedIndex;

            switch (index)
            {
            case 0:
                header = ClientHeader.CSayMsg;
                break;

            case 1:
                header = ClientHeader.CEmoteMsg;
                break;

            case 2:
                header = ClientHeader.CPlayerMsg;
                break;

            case 3:
                header = ClientHeader.CBroadcastMsg;
                break;
            }
        }
Beispiel #30
0
    public static ClientHeader GetHeader(MessageID x, int len)
    {
        ClientHeader header = new ClientHeader();

        header.m_iUin          = UIN;
        header.m_cSHFlag       = 0;
        header.m_nOptionLength = 0;
        header.m_szOption      = null;
        header.m_iMessageID    = (short)x;
        header.m_nPlayerID     = (short)Network.Myplayer.m_iPlayerUID;
        header.m_nGroupID      = 1;
        header.m_nPlatformID   = 0;

        lock (locker)
        {
            header.m_iSequenceID = SequenceID;
            Network.SequenceID++;
        }

        header.m_iPackageLength = 23 + header.m_nOptionLength + len;

        return(header);
    }