Exemple #1
0
        private void HandleGamePacket(object sender, PacketEventArgs e)
        {
            INetNode node = (INetNode)sender;

            if (e.Type == PacketType.Connect)
            {
                if (e.Data.Length != 0)
                {
                    return;
                }
                byte[] data = new byte [8];
                BitConv.ToInt32(data, 0, nodes.IndexOf(node));
                BitConv.ToInt32(data, 4, nodes.Count);
                node.SendPacket(PacketType.Accepted, data);
            }
            else if (e.Type == PacketType.DoomData)
            {
                if (e.Data.Length < 4)
                {
                    return;
                }
                int nodeid = BitConv.FromInt32(e.Data, 0);
                if (nodeid < 0 || nodeid >= nodes.Count)
                {
                    return;
                }
                byte[] data = new byte [e.Data.Length];
                BitConv.ToInt32(data, 0, nodes.IndexOf(node));
                Array.Copy(e.Data, 4, data, 4, e.Data.Length - 4);
                nodes[nodeid].SendPacket(PacketType.DoomData, data);
            }
        }
Exemple #2
0
 private void SendPacket(EndPoint endpoint, PacketType type, byte[] data)
 {
     byte[] buffer = new byte [HeaderSize + data.Length];
     BitConv.ToInt32(buffer, 0, Magic);
     buffer[4] = (byte)type;
     data.CopyTo(buffer, HeaderSize);
     socket.SendTo(buffer, endpoint);
 }