Esempio n. 1
0
 public void Leave(WorldSession session)
 {
     lock (players)
     {
         players.Remove(session);
         Players = players.ToArray();
     }
 }
Esempio n. 2
0
 protected void Join(WorldSession cs)
 {
     lock (players)
     {
         players.Add(cs);
         Players = players.ToArray();
     }
 }
Esempio n. 3
0
        public static bool IsBlockProtected(WorldSession session, WorldRegion r)
        {
            if (r == null)
                return false;

            if (session.Mode == GameMode.Creative && session.Player.Admin())
                return false;
            if (r.IsResident(session.Player))
                return false;

            switch (r.Type)
            {
                case Protected.Type:
                case Preserved.Type:
                case Adventure.Type:
                case Honeypot.Type:
                case SpawnRegion.Type:
                case WarpZone.Type:
                    return true;
            }

            return false;
        }
Esempio n. 4
0
 public void SendToAllBut(PacketFromServer packet, WorldSession player)
 {
     foreach (var p in Players)
     {
         if (p == player)
             continue;
         p.Send(packet);
     }
 }
Esempio n. 5
0
 internal static bool FilterServer(WorldSession player, Packet packet)
 {
     return packet.PacketID == TimeUpdate.ID;
 }
Esempio n. 6
0
 /// <summary>
 /// Player activities log
 /// </summary>
 public static void WritePlayer(WorldSession session, string message)
 {
     WritePlayer(session.Player, message);
 }
Esempio n. 7
0
        /// <summary>
        /// Find region and send message
        /// </summary>
        internal static void SetRegion(WorldSession session)
        {
            RegionList regions = session.World.Regions;
            if (regions == null)
                return;

            try
            {
                //This is called every single player movement, 20 times a second, some optimization might be needed.
                WorldRegion w = null;
                //First test if we are in the same as before
                WorldRegion current = session.CurrentRegion;
                if (current != null)
                {
                    if (current.Deleted == false && current.Contains(session.Position))
                    {
                        w = GetRegion(current.SubRegions, session.Position, session.Dimension);
                        if (w == null)
                            w = current;
                    }
                }
                if (w == null)
                    w = GetRegion(regions.List, session.Position, session.Dimension);
            
                //Debug.Write("Setregion: " + w);

                //If different
                if (session.CurrentRegion != w)
                {
                    //Leaving
                    if (session.CurrentRegion != null && (session.CurrentRegion.HasChild(w) == false))
                        session.CurrentRegion.Leaving(session.Player, w);

                    //Entering
                    if (w != null && w.HasChild(session.CurrentRegion) == false)
                        w.Entering(session.Player);

                    //Stats
                    SetStats(session.CurrentRegion, session.Player);
                    SetStats(w, session.Player);
                }
                //Adjust Survival/Adventure mode
                if (session.Mode != GameMode.Creative &&
                    session.Mode != GameMode.Spectator)
                {
                    bool protect = Protected.IsBlockProtected(session, w);
                    if (protect && w.IsResident(session.Player))
                        protect = false;
                    
                    if (protect)
                        session.SetMode(GameMode.Adventure);
                    else
                        session.SetMode(GameMode.Survival);
                }

                if (w != null && w.Type == WarpZone.Type)
                {
                    if (session.Mode != GameMode.Creative)
                    {
                        WarpZone wz = new WarpZone(w.Name);
                        session.Player.Warp(wz.Destination, (Dimensions)wz.DestinationDimension, wz.DesinationWorld);
                    }
                }

                bool update = (w != session.CurrentRegion);
                session.CurrentRegion = w;
                if (update)
                {
                    ScoreboardRegionManager.UpdateRegion(session.Player);
                }
#if !DEBUG
            } catch (Exception e)
            {
                Log.WriteServer(e);
                return;
#endif
            } finally
            {
            }
        }
Esempio n. 8
0
 void SessionClosed(WorldSession s, Exception e)
 {
     if (Phase == Phases.Gaming)
     {
         this.TellSystem(Chat.Red, "Session error: " + e.Message);
         if (s == Session)
             SetWorld(World.Construct);
     }
     else
     {
         SetWorld(World.Void);
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Special worlds where the entrance region matters
 /// such as banks and warpzones
 /// </summary>
 public void SetSession(WorldSession session)
 {
     lock (sessionLock)
     {
         WorldSession old = Session;
         Session = session;
         if (old != null)
             old.Close("going to " + session);
     }
 }
Esempio n. 10
0
        public static bool FilterServer(WorldSession player, Packet packet)
        {
            if (player.Mode == GameMode.Creative && player.Player.Admin())
                return false;
			
            byte pid = packet.PacketID;

            //Never stop raining
            if (pid == ChangeGameState.ID)
            {
                ChangeGameState ns = packet as ChangeGameState;
                if (ns.Reason == GameState.EndRaining)
                    return true;
            }
			
            //Block Time
            if (pid == TimeUpdate.ID)
            {
                player.Player.SendToClient(new TimeUpdate(18000));
                return true;
            }
			
            return false;
        }
Esempio n. 11
0
        /// <summary>
        /// Check for speed violations and update position
        /// </summary>
        internal void ClientMovement(WorldSession player, CoordDouble newPos)
        {
            CoordDouble diff = newPos - player.Position;
            diff.X = Math.Sqrt(diff.X * diff.X + diff.Z * diff.Z);
            //diff.Z = dt(later below)
            
#if !DEBUG
            //Ignore movements in Creative mode
            if (player.Mode == GameMode.Creative || player.Mode == GameMode.Spectator)
            {
                player.SetPositionServer(newPos);
                return;
            }
#endif
            
            //Movements if attached already ignored
            //Ignore movements withing the attached to item circle
            if (newPos.Y < -900)
            {
                return;
            }
            //Ignore initial position
            if (player.Position.Abs < 1)
                return;
            
            //For statistics, record all y positions
            //FreqAnalyzer.RecordStep (player, player.Position, newPos);
    
            //Ignore large client movements
            if (diff.X > 8 || diff.Y > 8)
            {
                //string msg = "Too large movement: " + player.Position + " to " + newPos;
                //Log.WritePlayer (player.Client, msg);
                
#if DEBUG
                //player.Tell(msg);
                //Console.WriteLine(DateTime.Now + " " + msg);
#endif
                diff = new CoordDouble();
            }

            //Calculate max speed during last update
            double sec = 0.05;
            CoordDouble max = new CoordDouble(0, 0, sec);
            //Effect index
            int ei = player.EffectSpeed.Active ? player.EffectSpeed.Amplifier + 1 : 0;
            double fac;
            if (player.Crouched)
                fac = LawsOfMinecraft.Crounch;
            else if (player.Sprinting)
                fac = LawsOfMinecraft.Sprint;
            else
                fac = LawsOfMinecraft.Walk;
            if (player.OnGround == false)
                fac += 4;
            double em = (ei - LawsOfMinecraft.ZeroSpeedEffect) * LawsOfMinecraft.SpeedEffectMultiplier * fac;

#if !DEBUG
            //em += 1.5; //Margin, useful for sprintjumping
#endif
            max.X = em * sec;
            if (em < LawsOfMinecraft.LadderSpeed)
#if DEBUG
                em = LawsOfMinecraft.LadderSpeed;
#else
                em = LawsOfMinecraft.LadderSpeed + 1;
#endif
            max.Y = em * sec;

            diff.Z = 0.05;
            HistoryLastDiff += diff;
            HistoryLastMax += max;

            DateTime step = DateTime.Now;
            if (HistoryLastStep.AddSeconds(1) < DateTime.Now)
            {
                if (HistoryLastStep == DateTime.MinValue)
                    HistoryLastStep = step.AddSeconds(-1);
                
                //Old length
                TimeSpan dt = step - HistoryLastStep;
                HistoryLastStep = step;
                HistoryLastDiff.Z = dt.TotalSeconds;
    
                //Speed calculation
                
                //Move forward one step
                for (int n = HistorySpeed.Length - 1; n > 0; n--)
                {
                    HistorySpeed [n] = HistorySpeed [n - 1];
                    HistoryMax [n] = HistoryMax [n - 1];
                }
                HistorySpeed [0] = HistoryLastDiff;
                HistoryMax [0] = HistoryLastMax;
                
                //Skip some ridicoulus speeds
                if (HistorySpeed [0].X > 20 || HistorySpeed [0].Y > 20)
                    HistorySpeed [0] = new CoordDouble();
                
                //Log distance
                player.Player.Settings.WalkDistance += HistoryLastDiff.X;

                HistoryLastDiff = new CoordDouble();
                HistoryLastMax = new CoordDouble();
                
                //Speed limits:
                //Currently no vehicle speeds are recorded here.
                //Ok, since they are controlled serverside anyway.
                
                CoordDouble acc = new CoordDouble();
                max = new CoordDouble();

                int a = 0;
                while (a < HistorySpeed.Length)
                {
                    
                    acc += HistorySpeed [a];
                    max += HistoryMax [a];
                    a++;
                    
                    //Step check
                    if (acc.X < max.X && acc.Y < max.Y)
                        break;

                    //Calibrated for time diff
                    if (acc.X / acc.Z < max.X / max.Z &&
                        acc.Y / acc.Z < max.Y / max.Z)
                        break;

                }

#if DEBUG
                string dmsg = a + " ";
                dmsg += HistorySpeed [0].ToString("0.00");
                dmsg += " / ";
                dmsg += HistoryMax [0].ToString("0.00");
                dmsg += " ";
                dmsg += player.Sprinting ? "S" : "s";
                dmsg += player.Crouched ? "C" : "c";
                dmsg += " E:";
                dmsg += player.EffectSpeed.Active ? "+" + player.EffectSpeed.Amplifier : "";
                dmsg += player.EffectSlow.Active ? "-" + player.EffectSlow.Amplifier : "";
                
                /*if (a <= 1)
                    player.Tell(Chat.Green, dmsg);
                else if (a <= 2)
                    player.Tell(Chat.Yellow, dmsg);
                else 
                    player.TellSystem(Chat.Red, dmsg);
*/
                //Console.WriteLine(player.Player.MinecraftUsername + " " + dmsg);
#endif      
                if (a <= 2)
                    return; //no violation whatsoever
            
                //Log.WritePlayer (player, "Speed " + a + " seconds");
                //for (int n = 0; n < HistorySpeed.Length; n++) {
                //  Log.WritePlayer (player, HistorySpeed [n].ToString ("0.00") + " / " + HistoryMax [n].ToString ("0.00"));
#if xDEBUG
                    Console.WriteLine(HistorySpeed [n].ToString ("0.00") + " / " + HistoryMax [n].ToString ("0.00"));
#endif      
                //}

                if (a < HistorySpeed.Length - 3)
                    return; //no visual speed warning
                
                player.Player.TellAbove(Chat.Aqua, "SLOW DOWN, speed mods are banned!");
                Chatting.Parser.TellAdmin(Chat.Aqua + player.Player.MinecraftUsername + " " + a + " s");
                Chatting.Parser.TellAdmin(Chat.Aqua + HistorySpeed [0].ToString("0.00") + " / " + HistoryMax [0].ToString("0.00"));
                
                if (a >= HistorySpeed.Length)
                {
#if DEBUG
                    player.TellSystem(Chat.Red, "Speed Ban triggered" + Chat.Yellow + " - only testing");
#else
                    player.Player.BanByServer(DateTime.Now.AddMinutes(30), "Moving too fast(modified client)");
#endif
                }
            }
        }