public static void SendToAll(PacketHandler p)
 {
     for (int i = 0; i < GridServer.player_list.Length; i++)
     {
         if (GridServer.player_list[i] != null)
         {
             GridServer.player_list[i].WaitToRead = true;
             GridServer.player_list[i].SendPacket(p, GridServer.player_list[i].id, ref GridServer.player_list[i], false, false);
         }
     }
 }
 public static void SendToPlayer(PacketHandler p, int id)
 {
     int i = 0;
     while (i < player_list.Length)
     {
         if (player_list[i] != null && player_list[i].id == id)
         {
             player_list[i].SendPacket(p, id, ref player_list[i], false, false);
         }
         i++;
     }
 }
        public PacketHandler OnPhysicsHandler(PacketType p_type, string CustomPacketType, ref PacketReader packet_reader, PacketHandler _p, ref ClientManager cm)
        {
            base.RunModuleCache();
            GridServer.player_list[cm.id].WaitToRead = false;
            HandlePhysics_start = new ThreadStart(DoPhysics);
            HandlePhysics = new Thread(HandlePhysics_start);
            _client = cm;
            id = cm.id;
            block = new BlockChangePacket(PacketType.BlockChange);
            block.BlockType = (byte)((PlayerBlockPlacementPacket)_p).BlockID.s_short;
            block.Metadata = 0x00;
            block.X = ((PlayerBlockPlacementPacket)_p).X;
            block.Y = ((PlayerBlockPlacementPacket)_p).Y;
            block.Z = ((PlayerBlockPlacementPacket)_p).Z;
            HandlePhysics.Start();

            return _p;
        }
Exemple #4
0
 public PacketHandler OnBlockChange(PacketType p_type, string CustomPacketType, ref PacketReader packet_reader, PacketHandler _p, ref ClientManager cm)
 {
     return _p;
 }
        public PacketHandler LoginPreChunkHandler(PacketType p_type, string CustomPacketType, ref PacketReader packet_reader, PacketHandler _p, ref ClientManager cm)
        {
            base.RunModuleCache();

            GridServer.player_list[cm.id].WaitToRead = false;
            send_start = new ThreadStart(DoChunks);
            send = new Thread(send_start);

            pr = packet_reader;
            _client = cm;
            id = cm.id;

            send.Start();

            return _p;
        }
 public void AddPacket(PacketHandler obj)
 {
 }
        public void SendPacket(PacketHandler p, int id, ref ClientManager cm, bool PingType, bool Waitread)
        {
            try
            {
                byte[] t_byte = p.GetBytes();
                if (PingType == false)
                {
                    Console.WriteLine("Packet Sent: " + p._packetid.ToString() + " Length: " + t_byte.Length);
                    GridServer.player_list[cm.id]._client.Client.SendBufferSize = t_byte.Length;
                    GridServer.player_list[cm.id]._client.Client.NoDelay = true;
                    GridServer.player_list[cm.id].Send(cm, t_byte);
                    if (GridServer.player_list[cm.id].keep_alive != null) GridServer.player_list[cm.id].keep_alive = DateTime.Now;
                    else
                    {
                        GridServer.player_list[cm.id].keep_alive = new DateTime();
                        GridServer.player_list[cm.id].keep_alive = DateTime.Now;

                    }
                    GridServer.player_list[cm.id].WaitToRead = Waitread;
                }
                else if (PingType == true)
                {
                    //Console.WriteLine("Packet Sent: " + p._packetid.ToString() + " Length: " + t_byte.Length);
                    byte[] temp = new byte[256];
                    t_byte.CopyTo(temp, 0);

                    GridServer.player_list[cm.id]._client.Client.SendBufferSize = t_byte.Length;
                    GridServer.player_list[cm.id]._client.Client.NoDelay = true;
                    GridServer.player_list[cm.id].Send(cm, temp);
                    GridServer.player_list[cm.id]._client.Close();
                    GridServer.player_list[cm.id].Stop(true);
                }
                else
                {
                    Console.WriteLine("Packet Sent: " + p._packetid.ToString() + " Length: " + t_byte.Length);

                    GridServer.player_list[cm.id]._client.Client.SendBufferSize = t_byte.Length;
                    GridServer.player_list[cm.id]._client.Client.NoDelay = true;
                    GridServer.player_list[cm.id].Send(cm, t_byte);
                    GridServer.player_list[cm.id].keep_alive = DateTime.Now;
                    GridServer.player_list[cm.id].WaitToRead = Waitread;
                }
            }
            catch (Exception e)
            {
                //Console.WriteLine("ERROR: " + e.Message + "\nSource:" + e.Source + "\nMethod:" + e.TargetSite + "\nData:" + e.Data + "\nStack trace:" + e.StackTrace);
                if (GridServer.player_list[id] != null)
                {
                    if (GridServer.player_list[id] != null)
                    {
                        GridServer.player_list[id].Stop(true);
                    }
                    else
                    {
                        this.Stop(true);
                    }
                }
                else
                {
                    this.Stop(true);
                }
            }
        }