示例#1
0
        public DisconnectHandshake(string message)
        {
            var msg = ChatMessageServer.CreateText(message);

            this.Message       = msg.Json;
            this.Message.Color = "red";
        }
示例#2
0
        protected override void Parse(EndianBinaryReader r)
        {
            string raw = ReadString8(r);

            //Debug.WriteLine("Chat RAW: " + raw);
            try {
                Json     = ChatJson.Parse(raw);
                Position = (ChatPosition)r.ReadByte();
            }
            #if !DEBUG
            catch (Exception ex) {
                Log.WriteServer(ex);
            }
            #endif
            finally {
            }
        }
示例#3
0
 protected override void Parse(EndianBinaryReader r)
 {
     Position = CoordInt.Read(r);
     try
     {
         Text1 = ChatJson.Parse(ReadString8(r));
         Text2 = ChatJson.Parse(ReadString8(r));
         Text3 = ChatJson.Parse(ReadString8(r));
         Text4 = ChatJson.Parse(ReadString8(r));
     }
     #if !DEBUG
     catch (Exception ex)
     {
         Log.WriteServer(ex);
     }
     #endif
     finally
     {
     }
 }
示例#4
0
 //Only parsed so we can block it
 protected override void Parse(EndianBinaryReader r)
 {
     Header = ChatJson.Parse(ReadString8(r));
     Footer = ChatJson.Parse(ReadString8(r));
 }
示例#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.GetPlayerByVanillaUUID(sp.PlayerUUID);
                    if (p != null)
                    {
                        Debug.WriteLine("SpawnPlayer changed from " + sp.PlayerUUID);
                        Debug.WriteLine("SpawnPlayer changed to   " + p.UUID);
                        sp.PlayerUUID = p.UUID;
                        sp.SetPacketBuffer(null);
                    }
                    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(Permissions.AnyAdmin))
                    {
                        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(Permissions.AnyAdmin) == 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
            {
            }
        }
示例#6
0
 protected override void Parse(EndianBinaryReader r)
 {
     Reason = ChatJson.Parse(ReadString8(r));
     Debug.WriteLine(this);
 }
示例#7
0
 public Disconnect(string message)
 {
     this.Reason      = new ChatJson();
     this.Reason.Text = message;
 }