Example #1
0
 /// <summary>
 /// To be called by Join(Client player)
 /// </summary>
 protected void Join(ConstructSession cs, Client player)
 {
     base.Join(cs);
     
     SendStartup(cs, player);
 
     //Dont show cloaked
     if (player.Settings.Cloaked != null)
         return;
     
     //Send named entity
     SpawnPlayer n = new SpawnPlayer(player.EntityID, player);
     n.Position = cs.Position;
     
     foreach (ConstructSession c in Players)
     {
         if (c == cs)
             continue;
         
         //Spawn new player in front of c
         c.Player.Queue.Queue(n);              
         Debug.WriteLine("Spawn " + n.PlayerUUID + " in front of " + c.Player.MinecraftUsername);
         
         //Spawn c in front of new player
         SpawnPlayer nes = new SpawnPlayer(
             c.Player.MinecraftUsername.GetHashCode(),
             c.Player);
         nes.Position = c.Position;
         nes.Pitch = c.Pitch;
         nes.Yaw = c.Yaw;
         
         cs.Player.Queue.Queue(nes);               
     }
 }
Example #2
0
        public static void SetCloak(Client player, string type)
        {
            if (type == null)
                player.Settings.Cloaked = null;
            else
            {
                try
                {
                    MobType mt = (MobType)Enum.Parse(typeof(MobType), type);
                    player.Settings.Cloaked = mt.ToString();

                    cloakBack.Remove(player.MinecraftUsername);
                    cloakBack.Add(player.MinecraftUsername, player.Session.Position);
                } catch (Exception)
                {
                    player.TellSystem(Chat.DarkRed, "Unknown mob: " + type);
                }
            }
            player.SaveProxyPlayer();
		
            VanillaSession rs = player.Session as VanillaSession;
            if (rs != null)
            {
                if (player.Settings.Cloaked == null)
                {
                    SpawnPlayer spawnNamedEntity = new SpawnPlayer(rs.EID, player);
                    spawnNamedEntity.Position = rs.Position;
                    spawnNamedEntity.Pitch = rs.Pitch;
                    spawnNamedEntity.Yaw = rs.Yaw;
                    rs.World.SendToAllBut(spawnNamedEntity, player.Session);

                    rs.Vanilla.Send("gamemode 0 " + player.MinecraftUsername);

                } else
                {
                    PlayerList.QueueToAll(new DestroyEntities(rs.EID));

                    rs.Vanilla.Send("gamemode 1 " + player.MinecraftUsername);
                }
            }

            TellMode(player);

            PlayerList.UpdateTabPlayers();
        }
Example #3
0
 public void UpdateEntity(SpawnPlayer spawn)
 {
     Player m = null;
     lock (entities)
     {
         if (entities.ContainsKey(spawn.EID))
             m = entities[spawn.EID] as Player;
         if (m == null)
         {
             m = new Player(spawn.EID, spawn.PlayerUUID);
             entities[spawn.EID] = m;
         }
     }
     m.Update(spawn);
 }
Example #4
0
		public void Update (SpawnPlayer spawn)
		{
		}
Example #5
0
        /// <summary>
        /// What the Server sends to the client
        /// </summary>
        protected virtual void FromServerGaming(PacketFromServer packet)
        {
            try
            {
                byte pid = packet.PacketID;

                if (pid == PassThrough.ID)
                {
                    Player.SendToClient(packet);
                    return;
                }

                //Before we rewrite the eid
                //Record all presented mobs, so far we have no method of cleaning this up so hold your thumbs
                if (pid == SpawnMob.ID)
                    World.Main.UpdateEntity((SpawnMob)packet);              
                if (pid == EntityMetadata.ID)
                    World.Main.UpdateEntity((EntityMetadata)packet);
                //if (pid == SpawnPlayer.ID)
                //World.Main.UpdateEntity((SpawnPlayer)packet);
                if (pid == SpawnObject.ID)
                    World.Main.UpdateEntity((SpawnObject)packet);
                if (pid == SpawnPainting.ID)
                    World.Main.UpdateEntity((SpawnPainting)packet);

                //Rewrite own EID, Fix eid to client eid player
                if (packet is IEntity)
                {
                    IEntity ie = (IEntity)packet;
                    if (ie.EID == EID)
                    {
                        ie.EID = Player.EntityID;
                        packet.SetPacketBuffer(null);
                    }
                }
                if (pid == SpawnObject.ID)
                {
                    var so = (SpawnObject)packet;
                    if (so.SourceEntity == EID)
                    {
                        so.SourceEntity = Player.EntityID;
                        packet.SetPacketBuffer(null);
                    }
                }

                //Region filters
                if (CurrentRegion != null && CurrentRegion.FilterServer(this, packet))
                    return;
                
                //Cloak and Nick
                if (Cloak.Filter(this, packet))
                    return;

                switch (pid)
                {
                    case SpawnPlayer.ID:
                        //Change reported uuid from offline to the known with names
                        var sp = (SpawnPlayer)packet;
                        var p = PlayerList.GetPlayerBySpawn(sp);
                        if (p != null)
                        {
                            Debug.WriteLine("SpawnPlayer changed from " + sp.PlayerUUID);
                            Debug.WriteLine("SpawnPlayer changed to   " + p.UUID);
                            sp.PlayerUUID = p.UUID;
                            sp.SetPacketBuffer(null);

                            //Naive attempt
                            sp = new SpawnPlayer(sp.EID, p);
                            sp.Position = sp.Position;
                            sp.Pitch = sp.Pitch;
                            sp.Yaw = sp.Yaw;
                        }
                        else
                            Debug.WriteLine("SpawnPlayer not changed: " + sp.PlayerUUID);

                        break;

                    case ChangeGameState.ID:
                        ChangeGameState ns = packet as ChangeGameState;
                        if (ns.Reason == GameState.BeginRaining || ns.Reason == GameState.EndRaining)
                            World.Main.Weather = ns;
                        if (ns.Reason == GameState.ChangeGameMode)
                            Mode = (GameMode)ns.Value;
                        break;

                    case SpawnObject.ID:
                        var so = (SpawnObject)packet;
                        if (so.Type != Vehicles.Item)
                            break;
                        OreTracker.Spawn(so, Position);
                        break;
                    case EntityMetadata.ID:
                        OreTracker.Track((EntityMetadata)packet);
                        break;

                    case EntityEffect.ID:
                        EntityEffect ee = (EntityEffect)packet;
                        if (ee.Effect == PlayerEffects.MoveSpeed)
                        {
                            EffectSpeed.Active = true;
                            EffectSpeed.Amplifier = ee.Amplifier;
                        }
                        if (ee.Effect == PlayerEffects.MoveSlowdown)
                        {
                            EffectSlow.Active = true;
                            EffectSlow.Amplifier = ee.Amplifier;
                        }
                        break;

                    case RemoveEntityEffect.ID:
                        RemoveEntityEffect re = (RemoveEntityEffect)packet;
                        if (re.Effect == PlayerEffects.MoveSpeed)
                            EffectSpeed.Active = false;
                        if (re.Effect == PlayerEffects.MoveSlowdown)
                            EffectSlow.Active = false;
                        break;
                
                    case TimeUpdate.ID:
                        World.Main.Time = packet as TimeUpdate;
                        break;

                    case UseBed.ID:
                        UseBed ub = (UseBed)packet;
                        if (ub.EID == Player.EntityID)
                            Sleeping = true;
                        break;

                //Waking up, among other things
                    case Animation.ID:
                        Animation a = (Animation)packet;
                        if (a.EID == Player.EntityID)
                        {
                            if (a.Animate == Animations.LeaveBed)
                                Sleeping = false;
                        }
                        break;
                                
#region Position and speed
                
                //Regions and player position
                    case PlayerPositionLookServer.ID:
                        var pp = (PlayerPositionLookServer)packet;
                        if (pp.Position.Y % 1 > 0.95)
                        {
                            //Console.WriteLine(pp.Position.ToString("0.00") + " " + pp.HeadY);
                            pp.Position.Y = Math.Ceiling(Position.Y);
                            //pp.HeadPosition = Position.Y + 1.62;
                            //Console.WriteLine(pp.Position.ToString("0.00") + " " + pp.Stance);
                            packet.SetPacketBuffer(null);
                        }
                        SetPosition(pp.Position, false);
                        break;

                    case Respawn.ID:
                        Dimension = ((Respawn)packet).Dimension;
                        SetPosition(Position, false);
                        break;                

                //Boats and carts
                    case AttachEntity.ID:
                        AttachEntity ae = (AttachEntity)packet;
                        if (ae.EID == Player.EntityID)
                        {
                            AttachedEntity = ae.VehicleID;
                        }
                        break;
                
                    case UpdateBlockEntity.ID:
                        if (Player.Admin())
                        {
                            var ute = (UpdateBlockEntity)packet;
                            if (ute.Action == UpdateBlockEntity.Actions.MobSpawner)
                            {
                                if (Spawners.Contains(ute.Pos) == false)
                                    Spawners.Add(ute.Pos);
                            }
                        }
                        break;

                    case EntityTeleport.ID:
                        if (AttachedEntity != 0)
                        {
                            EntityTeleport et = (EntityTeleport)packet;
                            if (et.EID == AttachedEntity)
                            {
                                SetPosition(et.Position, false);
                            }
                        }
                        break;

                    case EntityRelativeMove.ID:
                        if (AttachedEntity != 0)
                        {
                            EntityRelativeMove er = (EntityRelativeMove)packet;
                            if (er.EID == AttachedEntity)
                            {
                                SetPosition(Position + er.Delta, false);
                            }
                        }
                        break;                
#endregion

                    case ChatMessageServer.ID:
                        if (ServerParser.ParseServer(this.Player, (ChatMessageServer)packet))
                            return;
                        break;
                
                //Inventory
                    case WindowItems.ID:
                        var wi = (WindowItems)packet;
                        for (int n = 0; n < wi.Items.Length; n++)
                        {
                            if (wi.Items[n] == null)
                                continue;
                            if (wi.Items[n].Count > 64)
                            {
                                wi.Items[n] = null;
                                packet.SetPacketBuffer(null);
                            }
                        }
                        break;

                    case SetSlot.ID:
                        //Debug.WriteLine(packet);
                        SetSlot ss = (SetSlot)packet;

                        if (0 <= ss.Slot && ss.Slot < Inventory.Length)
                            Inventory[ss.Slot] = ss.Item;
                        break;

                //Tab player list items: Block Player, managed in PlayerList thread
                    case PlayerListItem.ID:
                        return;

                    case HeldItemServer.ID:
                //Active item
                        var hc = (HeldItemServer)packet;
                        if (hc.SlotID >= 0 && hc.SlotID <= 8)
                            ActiveInventoryIndex = hc.SlotID;
                        else
                            Log.Write(
                                new InvalidOperationException("Invalid holding slot id: " + hc.SlotID),
                                this.Player
                            );
                        break;

                //Keep a record of what window is open
                    case WindowOpen.ID:
                        WorldRegion r = LastClickRegion ?? CurrentRegion;
                        var wo = (WindowOpen)packet;
                        if (OpenWindows.ContainsKey(wo.WindowID))
                            OpenWindows.Remove(wo.WindowID);
                        OpenWindows.Add(wo.WindowID, new OpenWindowRegion(wo, r));

                        if (r == null || (Player.Admin() == false) && (Mode == GameMode.Creative))
                        {
                            //Leave unmodified
                        }
                        else
                        {
                            if (r.Type == Protected.Type &&
                                r.IsResident(Player) == false &&
                                wo.InventoryType != "CraftingTable" &&
                                wo.InventoryType != "Enchant" &&
                                wo.WindowTitle != "container.enderchest")
                            {
                                var cj = new ChatJson();
                                cj.Text = "Locked: " + r.Name;
                                wo.WindowTitle = cj.Serialize();
                                wo.SetPacketBuffer(null);
                            }
                        }
                        break;
                    
                //Turn off pvp when you die
                    case UpdateHealth.ID:
                        UpdateHealth uh = (UpdateHealth)packet;
                        if (Player.PvP && uh.Health <= 0)
                        {
                            Player.PvP = false;
                            Player.TellSystem(Chat.Purple, "PvP off");
                        }
                        break;
                
                
                    case WindowCloseServer.ID:
                        WindowClose((WindowCloseServer)packet);
                        break;

                //Disconnect while running the game
                //For disconnect at login see the handshake part
                    case Disconnect.ID:
                        Disconnect d = (Disconnect)packet;
                        if (d.Reason.Text == "Flying is not enabled on this server")
                        {
                            #if !DEBUG
                            Player.BanByServer(DateTime.Now.AddMinutes(2), d.Reason.Text);
                            #else
                            Chatting.Parser.Say(Chat.Yellow + Player.Name + Chat.Blue, " was kicked for flying");
                            #endif
                            return;
                        }
                        if (d.Reason.Text == "Internal server error")
                        {
                            Log.WritePlayer(
                                this.Player,
                                "Backend: Internal error - Restarting connection"
                            );
                            Player.SetWorld(World.Main);
                            return;
                        }
                        Player.SetWorld(World.Construct);
                        return;
                }
                //////////////Sending packet
                Player.SendToClient(packet);
                //////////////
                
#if !DEBUG
            } catch (Exception e)
            {
                thread.State = "ServerGamingException: " + e.Message;
                    
                Log.Write(e, this.Player);
                Player.Queue.Queue(packet);
#endif
            }
            finally
            {
            }
        }
Example #6
0
        public static Client GetPlayerBySpawn(SpawnPlayer sp)
        {
            Guid id = sp.PlayerUUID;
            int eid = sp.EID;

            foreach (Client p in List)
            {
                var vs = p.Session as VanillaSession;
                if (vs == null)
                    continue;
                if (vs.OfflineUUID == id)
                    return p;
                if (vs.EID == eid)
                    return p;
            }
            return null;
        }