/// <summary>
        /// Compares the value of this instance to a specified <see cref="ZonedDateTime"/> value and returns an integer
        /// that indicates whether this instance is earlier than, the same as, or later than the specified
        /// DateTime value.
        /// </summary>
        /// <param name="other">The object to compare to the current instance.</param>
        /// <returns>A signed number indicating the relative values of this instance and the value parameter.</returns>
        public int CompareTo(ZonedDateTime other)
        {
            if (ReferenceEquals(this, other))
            {
                return(0);
            }
            if (other is null)
            {
                return(1);
            }
            var thisEpochSeconds  = this.ToEpochSeconds() - OffsetSeconds;
            var otherEpochSeconds = other.ToEpochSeconds() - other.OffsetSeconds;
            var epochComparison   = thisEpochSeconds.CompareTo(otherEpochSeconds);

            if (epochComparison != 0)
            {
                return(epochComparison);
            }
            return(Nanosecond.CompareTo(other.Nanosecond));
        }
Exemplo n.º 2
0
        public void Recieve()
        {
            Nanosecond nano = new Nanosecond();
            //System.Diagnostics.
            int _id = id;
            System.GC.KeepAlive(GridServer.player_list[_id]);
            _stream = new NetworkStream(_client.Client);
            NetworkStream stream = new NetworkStream(_client.Client);
            PacketReader p_reader = new PacketReader(stream);
            //bool connected = true;
            while (GridServer.player_list[_id] != null && !GridServer.player_list[_id]._shouldStop)
            {
                if (nano.RunMiliSecond()) System.Threading.Thread.Sleep(1);
                try
                {
                    if (GridServer.player_list[_id] == null)
                    {
                        break;
                    }
                    if (GridServer.player_list[_id].Suspendv == false)
                    {
                        if (GridServer.player_list[_id]._client.Connected == false)
                        {
                            GridServer.player_list[_id].Stop(true);
                            return;
                        }
                        if (GridServer.player_list[_id]._client.Client.Available > 0)
                        {
                            //System.Threading.Thread.Sleep(1);
                            GridServer.player_list[_id].WaitToRead = true;
                            byte read = p_reader.ReadByte();
                            PacketType p_type = (PacketType)read;
                            //Console.WriteLine("Packet Recieved: " + p_type.ToString() + " Packet Byte:" + (byte)p_type);
                            if (ModuleHandler.Eventmodules.Keys.Contains(p_type))
                            {
                                Thread.BeginCriticalRegion();
                                ModuleHandler.Eventmodules[p_type](ref p_reader, p_type, ref GridServer.player_list[_id]);
                                Thread.EndCriticalRegion();
                                //GridServer.player_list[_id].WaitToRead = false;
                            }
                            else
                            {
                                System.Console.WriteLine(p_type.ToString() + " is not implemented:" + (byte)p_type);
                                byte[] unsupported_garbage = new byte[(int)p_reader.reader.Length];
                                p_reader.reader.Read(unsupported_garbage, 0, (int)p_reader.reader.Length);
                                GridServer.player_list[_id].WaitToRead = false;

                            }
                            if (GridServer.player_list[_id] != null && GridServer.player_list[_id]._stream != null && DateTime.Now.Minute > GridServer.player_list[_id].keep_alive.Minute || GridServer.player_list[_id].keep_alive.Second + 1 < DateTime.Now.Second)
                            {
                                Random r = new Random(1789);
                                if (GridServer.player_list[_id].customAttributes.ContainsKey("PayLoad"))
                                    GridServer.player_list[_id].customAttributes["PayLoad"] = (object)r.Next(1024, 4096);
                                LibOpenCraft.ServerPackets.KeepAlivePacket p = new LibOpenCraft.ServerPackets.KeepAlivePacket(PacketType.KeepAlive);
                                p.ID = (int)GridServer.player_list[_id].customAttributes["PayLoad"];
                                p.BuildPacket();
                                #region ProcessLatency
                                ms_latency.Start();
                                #endregion ProcessLatency
                                SendPacket(p, _id, ref GridServer.player_list[_id], false, false);
                            }

                        }
                        else
                        {
                            if (_player.name == "")
                                Thread.Sleep(50);
                            else
                            {
                                if (GridServer.player_list[_id]._player.EntityUpdateCount < (int)Config.Configuration["EntityUpdate"])
                                {
                                    ClientManager[] player = GridServer.player_list;
                                    for (int i = 0; i < player.Length; i++)
                                    {
                                        if (player[i] == null || player[i].id == _id || player[i].PreChunkRan != 1)
                                        {

                                        }
                                        else
                                        {
                                            LibOpenCraft.ServerPackets.EntityPacket e = new LibOpenCraft.ServerPackets.EntityPacket(PacketType.Entity);
                                            e.EntityID = _id;
                                            e.BuildPacket();
                                            player[i].SendPacket(e, player[i].id, ref player[i], false, false);
                                            GridServer.player_list[_id]._player.EntityUpdateCount++;
                                        }
                                    }
                                }
                                else
                                    GridServer.player_list[_id]._player.EntityUpdateCount = 0;
                            }
                        }
                    }
                }

                catch (Exception e)
                {
                    Console.WriteLine("ERROR: " + e.Message + "\nSource:" + e.Source + "\nMethod:" + e.TargetSite + "\nData:" + e.Data + "\nStackTrace:" + e.StackTrace);
                    if (GridServer.player_list[_id] != null)
                    {

                        GridServer.player_list[_id].Stop(true);
                    }
                    else
                    {
                        Stop(true);
                    }
                }
            }
        }