Esempio n. 1
0
    private void SendStop()
    {
        PacketMove pac = new PacketMove();

        pac.forward = Vector3.zero;
        pac.id      = id;
        Client.Instance.Send(pac);
    }
Esempio n. 2
0
    private void SendMove()
    {
        PacketMove pac = new PacketMove();

        pac.forward = BeforeForward;
        pac.id      = id;
        Client.Instance.Send(pac);
    }
Esempio n. 3
0
    public static void Process(Queue <Packet> queue, Client client)
    {
        while (queue.Count > 0)
        {
            Packet item = queue.Dequeue();

            if (item is PacketMessage)
            {
                PacketMessage packet = (PacketMessage)item;
            }
            if (item is PacketString)
            {
                PacketString packet = (PacketString)item;
                if (packet.key == "your id")
                {
                    Control con = (Control)PoolingManage.Pooling.Create("Control", Vector3.zero);
                    client.SetID(packet.value);
                    con.id = client.ID;
                }
                if (packet.key == "other id")
                {
                    if (packet.value == client.ID || GlobalData.Instance.m_list.Find(rhs => rhs.id == packet.value) != null)
                    {
                        continue;
                    }

                    Control con = (Control)PoolingManage.Pooling.Create("Control", Vector3.zero);
                    con.id = packet.value;
                    GlobalData.Instance.m_list.Add(con);
                }
                if (packet.key == "other ex")
                {
                    Control con = GlobalData.Instance.m_list.Find(rhs => rhs.id == packet.value);
                    GlobalData.Instance.m_list.Remove(con);
                    con.Remove();
                }
                if (packet.key == "ping")
                {
                    UIPing[] ping = PoolingManage.UIHud.GetList <UIPing>();
                    if (ping.Length > 0)
                    {
                        ping[0].Check();
                    }
                    Client.Instance.Send(packet);
                }
            }
            if (item is PacketTransform)
            {
                PacketTransform packet = (PacketTransform)item;
                if (packet.id == client.ID)
                {
                    continue;
                }

                Control con = GlobalData.Instance.m_list.Find(rhs => rhs.id == packet.id);
                if (con != null)
                {
                    con.transform.position    = packet.position;
                    con.transform.eulerAngles = packet.rotation;
                }
            }
            if (item is PacketMove)
            {
                PacketMove packet = (PacketMove)item;
                if (packet.id == client.ID)
                {
                    continue;
                }
                Control con = GlobalData.Instance.m_list.Find(rhs => rhs.id == packet.id);
                if (con != null)
                {
                    con.BeforeForward = packet.forward;
                }
            }
        }
    }
Esempio n. 4
0
    private void Receive(DataClient client)
    {
        Console.WriteLine(client.id + " connect");

        client.stream = new NetworkStream(client.socket);

        {
            PacketString packet = new PacketString();
            packet.key   = "your id";
            packet.value = client.id;
            Send(packet, client.id);
        }
        {
            PacketString packet = new PacketString();
            packet.key = "ping";
            Send(packet, client.id);
        }

        for (int i = 0; i < m_clientList.Count; ++i)
        {
            PacketString packet = new PacketString();
            packet.key   = "other id";
            packet.value = m_clientList[i].id;
            SendBroad(packet);
        }

        byte[] buff = new byte[BUFF_SIZ];

        while (true)
        {
            try
            {
                int length = client.stream.Read(buff, 0, buff.Length);
                if (length <= 0)
                {
                    ExitClient(client);
                    break;
                }

                int begin = 0;

                while (begin < length)
                {
                    Packet pac = PacketManager.GetPacket(PacketManager.GetPacketType(buff, begin), buff, begin);
                    begin += Marshal.SizeOf(pac);

                    if (pac is PacketTransform)
                    {
                        PacketTransform packet = (PacketTransform)pac;
                        SendBroad(packet, client);
                    }
                    if (pac is PacketMessage)
                    {
                        PacketMessage packet = (PacketMessage)pac;
                        Console.WriteLine(packet.data);
                    }
                    if (pac is PacketString)
                    {
                        PacketString packet = (PacketString)pac;
                        if (packet.key == "ping")
                        {
                            Send(packet, client.id);
                        }
                    }
                    if (pac is PacketMove)
                    {
                        PacketMove packet = (PacketMove)pac;
                        SendBroad(packet);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                ExitClient(client);
                break;
            }
        }
    }