示例#1
0
        public void HandleMessage(ScriptClient sender, PacketReader stream)
        {
            if (sender == null)
            {
                throw new ArgumentNullException(nameof(sender));
            }

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

            try
            {
                bool success = stream.ReadBit();
                if (success)
                {
                    CharacterCreationSuccessful?.Invoke(this);
                }
                else
                {
                    CharacterCreationFailure reason = (CharacterCreationFailure)stream.ReadByte();
                    CharacterCreationFailed?.Invoke(this, reason);
                }
            }
            catch (Exception e)
            {
                string msg = $"Something went wrong while handling a '{SupportedMessage}' script message from the server.";
                _Log.Error(msg);
                throw new ScriptMessageHandlingException(msg, e);
            }
        }
示例#2
0
        public CharacterCreation(IPacketWriterFactory writerFactory, ScriptMessageSender messageSender, CharacterCreationResultMessageHandler resultMessageHandler)
        {
            _WriterFactory = writerFactory ?? throw new ArgumentNullException(nameof(writerFactory));
            _MessageSender = messageSender ?? throw new ArgumentNullException(nameof(messageSender));

            resultMessageHandler.CharacterCreationFailed += (sender, args) =>
            {
                string msg;
                switch (args)
                {
                case CharacterCreationFailure.AlreadyExists:
                    msg = "Charactername bereits vergeben!";
                    break;

                case CharacterCreationFailure.NameIsInvalid:
                    msg = "Charactername ist ungültig!";
                    break;

                case CharacterCreationFailure.InvalidCreationInfo:
                    msg = "Fehlerhafte characterdaten(Netzwerkfehler?)!";
                    break;

                case CharacterCreationFailure.CharacterLimitReached:
                    msg = "Charakterlimit erreicht!";
                    break;

                default:
                    msg = "Unbekannter Fehler";
                    break;
                }
                CharacterCreationFailed?.Invoke(this, new CharacterCreationFailedArgs(msg));
            };

            resultMessageHandler.CharacterCreationSuccessful += sender => CharacterCreationSuccessful?.Invoke(this);
        }