Beispiel #1
0
        public static void Handle(Packet packet)
        {
            var deleteCharacterPacket = new DeleteCharacterPacket(packet);

            // Check if the user owns the character, if not don't do anything.
            var cid = CharacterModel.HasCharacter(LobbyServer.Instance.Database.Connection,
                                                  deleteCharacterPacket.CharacterName,
                                                  packet.Sender.User.Id);

            if (cid != 0)
            {
                CharacterModel.DeleteCharacter(LobbyServer.Instance.Database.Connection,
                                               cid, packet.Sender.User.Id);

                packet.Sender.Send(new DeleteCharacterAnswerPacket
                {
                    CharacterName = deleteCharacterPacket.CharacterName
                }.CreatePacket());

                return;
            }

#if DEBUG
            packet.Sender.SendError("This character doesn't belong to you!");
#else
            packet.Sender.KillConnection("Tried to delete a character he doesn't own");
#endif
        }
Beispiel #2
0
        private void HandleDeleteCharacterRequest(string username, PacketBase p)
        {
            DeleteCharacterPacket packet = (DeleteCharacterPacket)p;

            DeleteCharacterFailureType failureType = DeleteCharacterFailureType.Success;
            string path = _pathService.ServerVaultDirectory + username + "/" + packet.PCGlobalID;

            if (!File.Exists(path + ".pcf"))
            {
                _logger.Error($"PC file '{packet.PCGlobalID}' does not exist for username '{username}'. Cannot delete character. Ignoring request.");
                failureType = DeleteCharacterFailureType.FileDoesNotExist;
            }

            if (!_settingsService.AllowCharacterDeletion)
            {
                failureType = DeleteCharacterFailureType.ServerDoesNotAllowDeletion;
            }

            if (failureType == DeleteCharacterFailureType.Success)
            {
                // No hard deletes. Just rename the extension so it's not picked up by the engine.
                File.Move(path + ".pcf", path + ".dpcf");
            }

            CharacterDeletedPacket response = new CharacterDeletedPacket
            {
                PCGlobalID  = packet.PCGlobalID,
                FailureType = failureType
            };

            _networkService.SendMessage(PacketDeliveryMethod.ReliableUnordered, response, username);
        }
    //캐릭터 삭제 -> Server
    public void DeleteCharacter(int index)
    {
        Debug.Log("캐릭터 삭제");

        DeleteCharacterData   deleteCharacterData   = new DeleteCharacterData((byte)index);
        DeleteCharacterPacket deleteCharacterPacket = new DeleteCharacterPacket(deleteCharacterData);

        deleteCharacterPacket.SetPacketId((int)ClientPacketId.DeleteCharacter);

        DataPacket packet = new DataPacket(CreatePacket(deleteCharacterPacket), null);

        sendMsgs.Enqueue(packet);
    }
    //캐릭터 삭제
    public void DeleteCharacter(DataPacket packet)
    {
        Console.WriteLine(packet.client.RemoteEndPoint.ToString() + "캐릭터 삭제");

        DeleteCharacterPacket deleteCharacterPacket = new DeleteCharacterPacket(packet.msg);
        DeleteCharacterData   deleteCharacterData   = deleteCharacterPacket.GetData();

        string id = "";

        try
        {
            id = loginUser[packet.client];
        }
        catch
        {
            Console.WriteLine("Datahandler::DeleteCharacter.loginUser 에러");
        }

        UserData userData = database.GetUserData(id);
        Result   result   = Result.Fail;

        try
        {
            userData.DeleteHero(deleteCharacterData.Index);
            result = Result.Success;
        }
        catch
        {
            Console.WriteLine("DataHandler::DeleteCharacter.DeleteHero에러");
            result = Result.Fail;
        }

        database.FileSave(id + ".data", userData);

        ResultData   resultData       = new ResultData((byte)result);
        ResultPacket resultDataPacket = new ResultPacket(resultData);

        resultDataPacket.SetPacketId((int)ServerPacketId.DeleteChracterResult);

        byte[] msg = CreatePacket(resultDataPacket);
        packet = new DataPacket(msg, packet.client);

        lock (sendLock)
        {
            sendMsgs.Enqueue(packet);
        }
    }
        /// <summary>
        /// Marks character as deleted.
        /// </summary>
        private async void HandleDeleteCharacter(DeleteCharacterPacket characterDeletePacket)
        {
            var character = await _database.Characters.FirstOrDefaultAsync(c => c.UserId == _client.UserID && c.Id == characterDeletePacket.CharacterId);

            if (character is null)
            {
                return;
            }

            character.IsDelete   = true;
            character.DeleteTime = DateTime.UtcNow;

            await _database.SaveChangesAsync();

            using var packet = new Packet(PacketType.DELETE_CHARACTER);
            packet.WriteByte(0); // ok response
            packet.Write(character.Id);
            _client.SendPacket(packet);
        }
Beispiel #6
0
        public async Task Handle(WorldClient client, DeleteCharacterPacket packet)
        {
            var ok = await _selectionScreenManager.TryDeleteCharacter(client.UserId, packet.CharacterId);

            _packetFactory.SendDeletedCharacter(client, ok, packet.CharacterId);
        }
Beispiel #7
0
        public void DeleteCharPacketTest()
        {
            var packet = new DeleteCharacterPacket(Utilities.ConstructTestPacket("DeleteChar.bin", Shared.Network.Packets.CmdDeleteChar));

            StringAssert.AreEqualIgnoringCase("Administrator", packet.CharacterName);
        }