Exemplo n.º 1
0
    public static void Handle(ReceivablePacket packet)
    {
        switch (packet.ReadShort())
        {
        case 1:
            AccountAuthenticationResult.Process(packet);
            break;

        case 2:
            CharacterSelectionInfoResult.Process(packet);
            break;

        case 3:
            CharacterCreationResult.Process(packet);
            break;

        case 4:
            CharacterDeletionResult.Process(packet);
            break;

        case 5:
            PlayerOptionsInformation.Process(packet);
            break;

        case 6:
            PlayerInformation.Process(packet);
            break;

        case 7:
            NpcInformation.Process(packet);
            break;

        case 8:
            DeleteObject.Process(packet);
            break;

        case 9:
            Logout.Process(packet);
            break;

        case 10:
            LocationUpdate.Process(packet);
            break;

        case 11:
            AnimatorUpdate.Process(packet);
            break;

        case 12:
            ChatResult.Process(packet);
            break;

        case 13:
            PlayerInventoryUpdate.Process(packet);
            break;
        }
    }
Exemplo n.º 2
0
    public static void handle(ReceivablePacket packet)
    {
        switch (packet.ReadShort())
        {
        case 1:
            AccountAuthenticationResult.notify(packet);
            break;

        case 2:
            CharacterSelectionInfoResult.notify(packet);
            break;

        case 3:
            CharacterCreationResult.notify(packet);
            break;

        case 4:
            CharacterDeletionResult.notify(packet);
            break;

        case 5:
            EnterWorldInformation.notify(packet);
            break;

        case 6:
            PlayerInformation.notify(packet);
            break;

        case 7:
            DeleteObject.notify(packet);
            break;

        case 8:
            Logout.notify(packet);
            break;

        case 9:
            MoveToLocation.notify(packet);
            break;
        }
    }
Exemplo n.º 3
0
        public async void HandleMessage(Client.Client sender, PacketReader stream)
        {
            if (sender == null)
            {
                throw new ArgumentNullException(nameof(sender));
            }

            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            try
            {
                CharCreationInfo creationInfo = new CharCreationInfo();
                creationInfo.Read(stream);

                //Get the account session of the client.
                if (_AuthenticationService.TryGetSession(sender, out Session session))
                {
                    //Lets first check if the account can have an additional account(limit is taken from the rp config).
                    int charOwnershipsCount = await _CharacterService.GetCharacterOwnershipsCountAsync(session.Account);


                    if (charOwnershipsCount >= _RpConfig.MaxCharacterPerAccount)
                    {
                        using (var packet = _PacketWriterPool.GetScriptMessageStream(ScriptMessages.CharacterCreationResult))
                        {
                            packet.Write(false);
                            packet.Write((byte)CharacterCreationFailure.CharacterLimitReached);
                            sender.SendScriptMessage(packet, NetPriority.Medium, NetReliability.Reliable);
                        }
                        return;
                    }


                    //Create the new character.
                    CharacterCreationResult result =
                        await _CharacterService.CreateHumanPlayerCharacterAsync(creationInfo);



                    if (result is CharacterCreationFailed failed)
                    {
                        using (var packet = _PacketWriterPool.GetScriptMessageStream(ScriptMessages.CharacterCreationResult))
                        {
                            //Failure
                            packet.Write(false);
                            packet.Write((byte)failed.Reason);
                            sender.SendScriptMessage(packet, NetPriority.Medium, NetReliability.Reliable);
                        }
                    }
                    else if (result is CharacterCreationSuccess success)
                    {
                        //The character was created. Add an ownership entity and set the active character for account of the message sender.
                        await Task.WhenAll(new List <Task>
                        {
                            _CharacterService.AddCharacterOwnershipAsync(session.Account, success.Character),
                            _CharacterService.SetAccountActiveCharacterAsync(session.Account, success.Character)
                        });


                        using (var packet = _PacketWriterPool.GetScriptMessageStream(ScriptMessages.CharacterCreationResult))
                        {
                            //Success
                            packet.Write(true);
                            sender.SendScriptMessage(packet, NetPriority.Medium, NetReliability.Reliable);
                        }
                    }
                }
                else
                {
                    //This should not even be possible. Disconnect the client.
                    _Log.Error($"The client '{sender.SystemAddress}' tried to create a character while not being logged in(should never be possible)");
                    sender.Disconnect();
                }
            }
            catch (Exception e)
            {
                _Log.Error($"Something went wrong while handling a '{SupportedMessage}' message from the client '{sender.SystemAddress}'. Exception: {e}");
                sender.Disconnect();
            }
        }