Beispiel #1
0
 public PrivateChannelEventArgs(PrivateChannel channel, string character, bool joined, bool local)
 {
     this.Channel   = channel;
     this.Character = character;
     this.Joined    = joined;
     this.Local     = local;
 }
Beispiel #2
0
        public override void Execute(Server server, Context context)
        {
            //Arrange

            PrivateChannel privateChannel = server.Channels.GetPrivateChannelByOwner(Player);

            if (privateChannel != null)
            {
                Player observer = server.Map.GetPlayers()
                                  .Where(p => p.Name == Name)
                                  .FirstOrDefault();

                if (observer != null && observer != Player)
                {
                    if (!privateChannel.ContainsPlayer(observer) && !privateChannel.ContainsInvitation(observer))
                    {
                        //Act

                        privateChannel.AddInvitation(observer);

                        //Notify

                        context.Write(Player.Client.Connection, new ShowWindowTextOutgoingPacket(TextColor.GreenCenterGameWindowAndServerLog, observer.Name + " has been invited."));

                        context.Write(observer.Client.Connection, new ShowWindowTextOutgoingPacket(TextColor.GreenCenterGameWindowAndServerLog, Player.Name + " invites you to his private chat channel."));

                        base.Execute(server, context);
                    }
                }
            }
        }
Beispiel #3
0
        void _chat_PrivateChannelRequestEvent(Vha.Net.Chat chat, PrivateChannelRequestEventArgs e)
        {
            // Check for ignores
            if (this.Ignores.Contains(e.Character))
            {
                return;
            }
            // Some sensible checks
            PrivateChannel channel = e.GetPrivateChannel();
            bool           error   = false;

            lock (this._privateChannels)
            {
                error = this._privateChannels.ContainsKey(e.CharacterID);
            }
            if (error)
            {
                this.Write(MessageClass.Error, "Unexpected invite to private channel from: " + e.Character);
                return;
            }
            // Dispatch invite event
            PrivateChannelInviteEventArgs args = new PrivateChannelInviteEventArgs(e, channel);

            if (this.PrivateChannelInviteEvent != null)
            {
                this.PrivateChannelInviteEvent(this, args);
            }
        }
        public override void Execute(Server server, Context context)
        {
            //Arrange

            PrivateChannel privateChannel = server.Channels.GetPrivateChannelByOwner(Player);

            if (privateChannel == null)
            {
                //Act

                privateChannel = new PrivateChannel()
                {
                    Owner = Player,

                    Name = Player.Name + "'s channel"
                };

                privateChannel.AddPlayer(Player);

                server.Channels.AddChannel(privateChannel);
            }

            //Notify

            context.Write(Player.Client.Connection, new OpenMyPrivateChannelOutgoingPacket(privateChannel.Id, privateChannel.Name));

            base.Execute(server, context);
        }
        public async Task when_sending_packet_then_stream_receives_successfully()
        {
            var configuration = new MqttConfiguration();
            var stream        = new PrivateStream(configuration);
            var channel       = new PrivateChannel(stream, EndpointIdentifier.Client, configuration);

            var packetsReceived = 0;

            stream
            .Receive(EndpointIdentifier.Client)
            .Subscribe(packet => {
                packetsReceived++;
            });

            await channel.SendAsync(new byte[255]);

            await channel.SendAsync(new byte[10]);

            await channel.SendAsync(new byte[34]);

            await channel.SendAsync(new byte[100]);

            await channel.SendAsync(new byte[50]);

            await Task.Delay(TimeSpan.FromMilliseconds(1000));

            Assert.Equal(5, packetsReceived);
        }
        public void when_disposing_channel_then_became_disconnected()
        {
            var configuration = new MqttConfiguration();
            var stream        = new PrivateStream(configuration);
            var channel       = new PrivateChannel(stream, EndpointIdentifier.Server, configuration);

            channel.Dispose();

            Assert.False(channel.IsConnected);
        }
        public void when_creating_channel_with_stream_ready_then_it_is_connected()
        {
            var configuration = new MqttConfiguration();
            var stream        = new PrivateStream(configuration);
            var channel       = new PrivateChannel(stream, EndpointIdentifier.Client, configuration);

            Assert.True(channel.IsConnected);
            Assert.NotNull(channel.ReceiverStream);
            Assert.NotNull(channel.SenderStream);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BindablePrivateChannel"/> class.
        /// </summary>
        internal BindablePrivateChannel(
            IMessenger messenger,
            IClipboardService clipboardService,
            IDiscordService discordService,
            QuarrelClient quarrelClient,
            IDispatcherService dispatcherService,
            PrivateChannel privateChannel) :
            base(messenger, clipboardService, discordService, quarrelClient, dispatcherService, privateChannel)
        {
            SelectionCommand  = new RelayCommand(Select);
            JoinCallCommand   = new RelayCommand(JoinCall);
            MarkAsReadCommand = new RelayCommand(MarkRead);

            VoiceMembers = new ObservableCollection <BindableVoiceState>(
                privateChannel.GetVoiceStates()
                .Select(x => new BindableVoiceState(messenger, discordService, quarrelClient, dispatcherService, x)));

            _messenger.Register <MyVoiceStateUpdatedMessage>(this, (_, m) =>
            {
                IsConnected = m.VoiceState.Channel?.Id == Id;
            });
            _messenger.Register <VoiceStateAddedMessage>(this, (_, m) =>
            {
                if (m.VoiceState.Channel?.Id == Id)
                {
                    _dispatcherService.RunOnUIThread(() =>
                    {
                        var state = new BindableVoiceState(
                            _messenger,
                            _discordService,
                            _quarrelClient,
                            _dispatcherService,
                            m.VoiceState);

                        VoiceMembers.Add(state);
                    });
                }
            });
            _messenger.Register <VoiceStateRemovedMessage>(this, (_, m) =>
            {
                if (m.VoiceState.Channel?.Id == Id)
                {
                    _dispatcherService.RunOnUIThread(() =>
                    {
                        VoiceMembers.Remove(VoiceMembers.FirstOrDefault(x =>
                                                                        x.State.User?.Id == m.VoiceState.User?.Id));
                    });
                }
            });
        }
Beispiel #9
0
        public override void Execute(Server server, Context context)
        {
            //Arrange

            Channel channel = server.Channels.GetChannel(ChannelId);

            if (channel != null)
            {
                //Act

                if (channel.ContainsPlayer(Player))
                {
                    channel.RemovePlayer(Player);
                }

                PrivateChannel privateChannel = channel as PrivateChannel;

                if (privateChannel != null)
                {
                    if (privateChannel.Owner == Player)
                    {
                        foreach (var observer in privateChannel.GetPlayers().ToList())
                        {
                            context.Write(observer.Client.Connection, new CloseChannelOutgoingPacket(channel.Id));

                            privateChannel.RemovePlayer(observer);
                        }

                        foreach (var observer in privateChannel.GetInvitations().ToList())
                        {
                            privateChannel.RemoveInvitation(observer);
                        }

                        server.Channels.RemoveChannel(privateChannel);
                    }
                }

                //Notify

                context.Write(Player.Client.Connection, new CloseChannelOutgoingPacket(channel.Id));

                base.Execute(server, context);
            }
        }
        public async Task when_sending_to_stream_then_channel_receives_successfully()
        {
            MqttConfiguration configuration = new MqttConfiguration();
            PrivateStream     stream        = new PrivateStream(configuration);
            PrivateChannel    channel       = new PrivateChannel(stream, EndpointIdentifier.Server, configuration);

            int packetsReceived = 0;

            channel.ReceiverStream.Subscribe(packet =>
            {
                packetsReceived++;
            });

            stream.Send(new byte[255], EndpointIdentifier.Client);
            stream.Send(new byte[10], EndpointIdentifier.Client);
            stream.Send(new byte[34], EndpointIdentifier.Client);
            stream.Send(new byte[100], EndpointIdentifier.Client);
            stream.Send(new byte[50], EndpointIdentifier.Client);

            await Task.Delay(TimeSpan.FromMilliseconds(1000));

            5.Should().Be(packetsReceived);
        }
Beispiel #11
0
        void _chat_PrivateChannelStatusEvent(Vha.Net.Chat chat, PrivateChannelStatusEventArgs e)
        {
            PrivateChannel channel = e.GetPrivateChannel();

            // Handle locally
            if (e.Local)
            {
                bool joined = false;
                bool left   = false;
                lock (this._guests)
                {
                    if (this._guests.Contains(e.CharacterID) && !e.Join)
                    {
                        left = true;
                        this._guests.Remove(e.CharacterID);
                    }
                    else if (!this._guests.Contains(e.CharacterID) && e.Join)
                    {
                        joined = true;
                        this._guests.Add(e.CharacterID);
                    }
                }
                // Dispatch events
                if (this.CharacterJoinEvent != null && joined)
                {
                    this.CharacterJoinEvent(this, new PrivateChannelEventArgs(channel, e.Character, true, true));
                }
                if (this.CharacterLeaveEvent != null && left)
                {
                    this.CharacterLeaveEvent(this, new PrivateChannelEventArgs(channel, e.Character, false, true));
                }
            }
            // Handle remote
            else
            {
                // Handle other characters
                if (e.CharacterID != this.CharacterID)
                {
                }
                // Handle the local character
                else
                {
                    bool joined = false;
                    bool left   = false;
                    lock (this._privateChannels)
                    {
                        if (this._privateChannels.ContainsKey(e.ChannelID) && !e.Join)
                        {
                            left = true;
                            this._privateChannels.Remove(e.ChannelID);
                        }
                        else if (!this._privateChannels.ContainsKey(e.ChannelID) && e.Join)
                        {
                            joined = true;
                            this._privateChannels.Add(e.ChannelID, channel);
                        }
                    }
                    // Dispatch events
                    if (joined)
                    {
                        if (this.PrivateChannelJoinEvent != null)
                        {
                            this.PrivateChannelJoinEvent(this, new PrivateChannelEventArgs(channel, e.Character, true, false));
                        }
                    }
                    else if (left)
                    {
                        if (this.PrivateChannelLeaveEvent != null)
                        {
                            this.PrivateChannelLeaveEvent(this, new PrivateChannelEventArgs(channel, e.Character, false, false));
                        }
                    }
                    else
                    {
                        // Nothing happened, don't bother writing that message!
                        return;
                    }
                }
            }
            // Send messages
            if (e.Join)
            {
                this.Write(new MessageSource(MessageType.PrivateChannel, e.Channel, null, false), MessageClass.PrivateChannel,
                           e.Character + " joined the channel");
            }
            else
            {
                this.Write(new MessageSource(MessageType.PrivateChannel, e.Channel, null, false), MessageClass.PrivateChannel,
                           e.Character + " left the channel");
            }
        }
        public override void Execute(Server server, Context context)
        {
            //Arrange

            Channel channel = server.Channels.GetChannel(ChannelId);

            if (channel != null)
            {
                PrivateChannel privateChannel = channel as PrivateChannel;

                if (privateChannel != null)
                {
                    if (!privateChannel.ContainsPlayer(Player))
                    {
                        if (!privateChannel.ContainsInvitation(Player))
                        {
                            return;
                        }

                        //Act

                        privateChannel.RemoveInvitation(Player);

                        privateChannel.AddPlayer(Player);
                    }

                    //Notify

                    context.Write(Player.Client.Connection, new OpenChannelOutgoingPacket(privateChannel.Id, privateChannel.Name));

                    base.Execute(server, context);
                }
                else
                {
                    GuildChannel guildChannel = channel as GuildChannel;

                    if (guildChannel != null)
                    {
                        if (!guildChannel.ContainsPlayer(Player))
                        {
                            //Act

                            guildChannel.AddPlayer(Player);
                        }

                        //Notify

                        context.Write(Player.Client.Connection, new OpenChannelOutgoingPacket(guildChannel.Id, guildChannel.Name));

                        base.Execute(server, context);
                    }
                    else
                    {
                        PartyChannel partyChannel = channel as PartyChannel;

                        if (partyChannel != null)
                        {
                            if (!partyChannel.ContainsPlayer(Player))
                            {
                                //Act

                                partyChannel.AddPlayer(Player);
                            }

                            //Notify

                            context.Write(Player.Client.Connection, new OpenChannelOutgoingPacket(partyChannel.Id, partyChannel.Name));

                            base.Execute(server, context);
                        }
                        else
                        {
                            if (!channel.ContainsPlayer(Player))
                            {
                                //Act

                                channel.AddPlayer(Player);
                            }

                            //Notify

                            if (channel.Id == 3)
                            {
                                context.Write(Player.Client.Connection, new OpenRuleViolationsChannelOutgoingPacket(channel.Id));

                                foreach (var ruleViolation in server.RuleViolations.GetRuleViolations())
                                {
                                    if (ruleViolation.Assignee == null)
                                    {
                                        context.Write(Player.Client.Connection, new ShowTextOutgoingPacket(0, ruleViolation.Reporter.Name, ruleViolation.Reporter.Level, TalkType.ReportRuleViolationOpen, ruleViolation.Time, ruleViolation.Message));
                                    }
                                }
                            }
                            else
                            {
                                context.Write(Player.Client.Connection, new OpenChannelOutgoingPacket(channel.Id, channel.Name));
                            }

                            base.Execute(server, context);
                        }
                    }
                }
            }
        }
Beispiel #13
0
 public PrivateChannelInviteEventArgs(PrivateChannelRequestEventArgs evnt, PrivateChannel channel)
 {
     this._event  = evnt;
     this.Channel = channel;
 }
        private static void listRelationships()
        {
            retryRelationshipSelection :;
            Console.Clear();
            int i = 0;

            foreach (PrivateChannel rel in Storage.ReadyEvent.d.private_channels)
            {
                try
                {
                    Console.WriteLine("{0}|{1}#{2}", i++, rel.recipients[0].username, rel.recipients[0].discriminator);
                }
                catch
                {
                    //pass
                }
            }
            int gp = 0;

            Console.Write("\nSelect a relationship via number: ");
            string relSelect = Console.ReadLine();

            if (relSelect.ToUpper() == "BCK")
            {
                return;
            }
            int.TryParse(relSelect, out gp);
            if (gp < 0)
            {
                goto retryRelationshipSelection;
            }

            PrivateChannel relationship = Storage.ReadyEvent.d.private_channels[gp];

            currentChannel = new Channel {
                id = relationship.id
            };
            RewriteTitle(relationship.recipients[0].username);

retryCommandInput:
            WriteMessages();
            string commandlist = Console.ReadLine();
            string command     = commandlist.Substring(0, 3).ToUpper();

            switch (command)
            {
            default:
                Console.WriteLine("Error, command not recognized, try the hlp command.");
                goto retryCommandInput;

            case "MSG":
                currentChannel.PostMessage(commandlist.Substring(4, commandlist.Length - 4), false);
                goto retryCommandInput;

            case "HLP":
                printHelp();
                goto retryCommandInput;

            case "BCK":
                currentChannel = null;
                goto retryRelationshipSelection;

            case "LOD":
                messages.Clear();
                messages = currentChannel.GetPastMessagesList(15);
                goto retryCommandInput;

            case "CLR":
                messages.Clear();
                goto retryCommandInput;
            }
        }