Beispiel #1
0
        private AttachEntity ToAttach(DataRow attachRow)
        {
            AttachEntity attach = new AttachEntity(attachRow["ID"].ToString(), attachRow["ATT_NAME"].ToString());

            attach.Blob = SelAttachBlob(attach.Id);
            return(attach);
        }
        public void OnAddAttaches(bool moveToArchive)
        {
            _logger.Debug("OnAddAttaches");

            try
            {
                using (OpenFileDialog openDialog = new OpenFileDialog())
                {
                    openDialog.Multiselect      = true;
                    openDialog.RestoreDirectory = true;
                    System.Windows.Forms.DialogResult result = openDialog.ShowDialog();
                    if (result != System.Windows.Forms.DialogResult.OK || openDialog.FileNames == null || openDialog.FileNames.Length == 0)
                    {
                        return;
                    }

                    List <AttachEntity> attaches     = new List <AttachEntity>();
                    List <string>       fileNameList = new List <string>();
                    foreach (string fileName in openDialog.FileNames)
                    {
                        byte[] bytes = FileHlp.ReadFile(fileName);

                        AttachEntity attach = new AttachEntity();
                        attach.DateCreate = DateTime.Now;
                        attach.Name       = Path.GetFileName(fileName);
                        attach.Blob       = bytes;
                        attaches.Add(attach);

                        fileNameList.Add(fileName);
                    }
                    foreach (AttachEntity attach in attaches)
                    {
                        Request.Attaches.Entities.Add(attach);
                    }

                    if (moveToArchive)
                    {
                        AttachEntity attach = new AttachEntity();
                        attach.DateCreate = DateTime.Now;
                        attach.Name       = "Archive_req_" + Request.Id + ".zip";
                        attach.Blob       = FileHlp.AddToArchive(fileNameList);
                        Request.Attaches.Entities.Add(attach);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                _messageBoxMgr.ShowMessageWithDetail(LogLevel.Error, "Помилка під час додавання додатків до зверенння.", Hlp.GetExceptionText(ex), "Помилка", null);
            }
        }
 private void AttachEntityBindingSource_CurrentChanged(object sender, EventArgs e)
 {
     if (AttachEntityBindingSource.Current != null && QuickViewAttachButton.Checked)
     {
         AttachEntity entity = AttachEntityBindingSource.Current as AttachEntity;
         string       ext    = Path.GetExtension(entity.Name);
         if (ext == ".html" || ext == ".htm")
         {
             AttachHtmlPanel.Document.HtmlText = Encoding.Default.GetString(entity.Blob);
         }
         else
         {
             AttachHtmlPanel.Document.Text = "";
         }
     }
 }
        private void SaveAttachWithDialog(string dirPath, AttachEntity attach)
        {
            string fullPath = Path.Combine(dirPath, attach.Name);

            using (SaveFileDialog saveDialog = new SaveFileDialog())
            {
                saveDialog.FileName         = fullPath;
                saveDialog.InitialDirectory = dirPath;
                saveDialog.OverwritePrompt  = true;
                if (saveDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    using (System.IO.Stream s = saveDialog.OpenFile())
                    {
                        s.Write(attach.Blob, 0, attach.Blob.Length);
                    }
                }
            }
        }
Beispiel #5
0
        public void InsReqAttach(string requestId, AttachEntity attach)
        {
            _logger.Debug("InsReqAttach.");
            if (string.IsNullOrEmpty(requestId))
            {
                throw new ArgumentNullException("RequestId param can not be null.");
            }
            if (attach == null)
            {
                throw new ArgumentNullException("Attach param can not be null.");
            }
            _logger.Debug("Params: requestId = {0}; attach = {1};", requestId, attach.ToInternalString());

            OraCommand command = new OraCommand("REQ_PKG.INS_REQ_ATT");

            command.CommandType = CommandType.StoredProcedure;
            command.AddDBParam(new OraParamInt32("p_req_id", ParameterDirection.Input, Convert.ToInt32(requestId)));
            command.AddDBParam(new OraParamString("p_att_name", ParameterDirection.Input, attach.Name));
            command.AddDBParam(new OraParamBLOB("p_att_data", ParameterDirection.Input, attach.Blob));
            Execute(command);
        }
Beispiel #6
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
            {
            }
        }
 public void OnAttachEntity(AttachEntity packet)
 {
 }
 private void InvokeAttachEntity(AttachEntity packet)
 {
     packetListener.OnAttachEntity(packet);
 }
Beispiel #9
0
        public void NetThread()
        {
            SessionIDRequest sessionID = new SessionIDRequest(Storage.Network.UserName, Storage.Network.Password);

            sessionID.SendRequest();

            SharedSecretGenerator sharedSecret = new SharedSecretGenerator();              //random byte[16] gen

            Timer positionUpdater = new Timer(PositionSender, null, Timeout.Infinite, 50); //create position updater

            Socket networkSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            networkSocket.Connect(Storage.Network.Server, Storage.Network.Port);
            _stream = new EnhancedStream(networkSocket);

            Handshake handshake = new Handshake(_stream);

            handshake.Send(Storage.Network.UserName, Storage.Network.Server, Storage.Network.Port); // connect

            Storage.Network.IsConnected = true;

            while (Storage.Network.IsConnected)
            {
                switch (_packetIDbuffer = (byte)_stream.ReadByte())
                {
                case 0x00:
                    KeepAlive keepAlive = new KeepAlive(_stream);
                    break;

                case 0x01:
                    LoginRequest loginRequest = new LoginRequest(_stream);
                    //positionUpdater.Change(0, 50);
                    ClientSettings clientSettings = new ClientSettings(_stream);
                    clientSettings.Send();
                    break;

                case 0x03:
                    ChatMessage chatMessage = new ChatMessage(_stream);
                    break;

                case 0x04:
                    TimeUpdate timeUpdate = new TimeUpdate(_stream);
                    break;

                case 0x05:
                    EntityEquipment entityEquipment = new EntityEquipment(_stream);
                    break;

                case 0x06:
                    SpawnPosition spawnPosition = new SpawnPosition(_stream);
                    break;

                case 0x08:
                    UpdateHealth updateHealth = new UpdateHealth(_stream);
                    break;

                case 0x09:
                    RespawnPacket respawnPacket = new RespawnPacket(_stream);
                    break;

                case 0x0D:
                    _playerPositionLook = new PlayerPositionLook(_stream);
                    break;

                case 0x10:
                    HeldItemChange heldItemChange = new HeldItemChange(_stream);
                    break;

                case 0x11:
                    UseBed useBed = new UseBed(_stream);
                    break;

                case 0x12:
                    Animation animation = new Animation(_stream);
                    break;

                case 0x14:
                    SpawnNamedEntity spawnNamedEntity = new SpawnNamedEntity(_stream);
                    break;

                case 0x16:
                    CollectItem collectItem = new CollectItem(_stream);
                    break;

                case 0x17:
                    SpawnObjectVehicle spawnObjectVehicle = new SpawnObjectVehicle(_stream);
                    break;

                case 0x18:
                    SpawnMob spawnMob = new SpawnMob(_stream);
                    break;

                case 0x19:
                    SpawnPainting spawnPainting = new SpawnPainting(_stream);
                    break;

                case 0x1A:
                    SpawnExperienceOrb spawnExperienceOrb = new SpawnExperienceOrb(_stream);
                    break;

                case 0x1C:
                    EntityVelocity entityVelocity = new EntityVelocity(_stream);
                    break;

                case 0x1D:
                    DestroyEntity destroyEntity = new DestroyEntity(_stream);
                    break;

                case 0x1E:
                    Entity entity = new Entity(_stream);
                    break;

                case 0x1F:
                    EntityRelativeMove entityRelativeMove = new EntityRelativeMove(_stream);
                    break;

                case 0x20:
                    EntityLook entityLook = new EntityLook(_stream);
                    break;

                case 0x21:
                    EntityLookRelativeMove entityLookRelativeMove = new EntityLookRelativeMove(_stream);
                    break;

                case 0x22:
                    EntityTeleport entityTeleport = new EntityTeleport(_stream);
                    break;

                case 0x23:
                    EntityHeadLook entityHeadLook = new EntityHeadLook(_stream);
                    break;

                case 0x26:
                    EntityStatus entityStatus = new EntityStatus(_stream);
                    break;

                case 0x27:
                    AttachEntity attachEntity = new AttachEntity(_stream);
                    break;

                case 0x28:
                    EntityMetadata entityMetadata = new EntityMetadata(_stream);
                    break;

                case 0x29:
                    EntityEffect entityEffect = new EntityEffect(_stream);
                    break;

                case 0x2A:
                    RemoveEntityEffect removeEntityEffect = new RemoveEntityEffect(_stream);
                    break;

                case 0x2B:
                    SetExperience setExperience = new SetExperience(_stream);
                    break;

                case 0x33:
                    ChunkData mapChunk = new ChunkData(_stream);
                    break;

                case 0x34:
                    MultiBlockChange multiBlockChange = new MultiBlockChange(_stream);
                    break;

                case 0x35:
                    BlockChange blockChange = new BlockChange(_stream);
                    break;

                case 0x36:
                    BlockAction blockAction = new BlockAction(_stream);
                    break;

                case 0x37:
                    BlockBreakAnimation blockBreakAnimation = new BlockBreakAnimation(_stream);
                    break;

                case 0x38:
                    MapChunkBulk mapChunkBulk = new MapChunkBulk(_stream);
                    break;

                case 0x3C:
                    Explosion explosion = new Explosion(_stream);
                    break;

                case 0x3D:
                    SoundParticleEffect soundParticleEffect = new SoundParticleEffect(_stream);
                    break;

                case 0x3E:
                    NamedSoundEffect namedSoundEffect = new NamedSoundEffect(_stream);
                    break;

                case 0x46:
                    ChangeGameState changeGameState = new ChangeGameState(_stream);
                    break;

                case 0x47:
                    Thunderbolt thunderbolt = new Thunderbolt(_stream);
                    break;

                case 0x64:
                    OpenWindow openWindow = new OpenWindow(_stream);
                    break;

                case 0x65:
                    CloseWindow closeWindow = new CloseWindow(_stream);
                    break;

                case 0x67:
                    SetSlot setSlot = new SetSlot(_stream);
                    break;

                case 0x68:
                    SetWindowItems setWindowItems = new SetWindowItems(_stream);
                    break;

                case 0x69:
                    UpdateWindowProperty updateWindowProperty = new UpdateWindowProperty(_stream);
                    break;

                case 0x6A:
                    ConfirmTransaction confirmTransaction = new ConfirmTransaction(_stream);
                    break;

                case 0x6B:
                    CreativeInventoryAction creativeInventoryAction = new CreativeInventoryAction(_stream);
                    break;

                case 0x6C:
                    EnchantItem enchantItem = new EnchantItem(_stream);
                    break;

                case 0x82:
                    UpdateSign updateSign = new UpdateSign(_stream);
                    break;

                case 0x83:
                    ItemData itemData = new ItemData(_stream);
                    break;

                case 0x84:
                    UpdateTileEntity updateTileEntity = new UpdateTileEntity(_stream);
                    break;

                case 0xC8:
                    IncrementStatistic incrementStatistic = new IncrementStatistic(_stream);
                    break;

                case 0xC9:
                    PlayerListItem playerListItem = new PlayerListItem(_stream);
                    break;

                case 0xCA:
                    PlayerAbilities playerAbilities = new PlayerAbilities(_stream);
                    break;

                case 0xCB:
                    TabComplete tabcomplete = new TabComplete(_stream);
                    break;

                case 0xFA:
                    PluginMessage pluginMessage = new PluginMessage(_stream);
                    break;

                case 0xFC:
                    EncryptionKeyResponse encryptionKeyResponse = new EncryptionKeyResponse(_stream);
                    encryptionKeyResponse.Get();
                    _stream = new AesStream(networkSocket, _stream, sharedSecret.Get);
                    ClientStatuses clientStatuses = new ClientStatuses(_stream);
                    clientStatuses.Send(0);
                    break;

                case 0xFD:
                    EncryptionKeyRequest encryptionKeyRequest = new EncryptionKeyRequest(_stream, sharedSecret.Get, sessionID.GetID(), Storage.Network.UserName);     //
                    encryptionKeyResponse = new EncryptionKeyResponse(_stream);
                    encryptionKeyResponse.Send(encryptionKeyRequest.GetEncSharedSecret(), encryptionKeyRequest.GetEncToken());
                    break;

                case 0xFF:
                    positionUpdater = null;
                    DisconnectKick disconnectKick = new DisconnectKick(_stream);
                    networkSocket.Disconnect(false);
                    break;

                default:
                    throw new Exception("We got a Unknown Packet (" + _packetIDbuffer + ")from the Server. This should not happen: Error in Packet parser");
                }
            }
        }