public override void ChannelActive(IChannelHandlerContext contex)
        {
            IChannelGroup g = _group;

            if (g == null)
            {
                lock (this)
                {
                    if (_group == null)
                    {
                        g = _group = new DefaultChannelGroup(contex.Executor);
                    }
                }
            }
            g?.Add(contex.Channel);
            _poker.Player += 1;
            _poker.AddPlayer(_poker.Player, contex.Channel.RemoteAddress.ToString());
            //contex.WriteAndFlushAsync(g.Count);
            if (_poker.Player == 4)
            {
                contex.WriteAndFlushAsync("Welcome to the game!\n");
                _group.WriteAndFlushAsync("Welcome to the game\n", new EveryOneBut(contex.Channel.Id));
                _poker.IsGameStarted = true;
            }
            Console.WriteLine(_poker.Player);
        }
        public static void SendPackets(this IChannelGroup channelGroup, IEnumerable <PacketDefinition> packets, IChannelMatcher matcher)
        {
            var packetDefinitions = packets as PacketDefinition[] ?? packets.ToArray();

            if (packetDefinitions.Length == 0)
            {
                return;
            }

            if (matcher == null)
            {
                channelGroup?.WriteAndFlushAsync(PacketFactory.Serialize(packetDefinitions));
            }
            else
            {
                channelGroup?.WriteAndFlushAsync(PacketFactory.Serialize(packetDefinitions), matcher);
            }
        }
Beispiel #3
0
        protected override void ChannelRead0(IChannelHandlerContext context, string msg)
        {
            context.WriteAndFlushAsync($"[you] {msg}\n");
            _group.WriteAndFlushAsync($"[{context.Channel.RemoteAddress}] {msg}", new ExcludeChannelMatcher(context.Channel.Id));

            if (msg.Equals("quit", StringComparison.InvariantCultureIgnoreCase))
            {
                context.Channel.CloseAsync();
            }
        }
        protected override void ChannelRead0(IChannelHandlerContext contex, string msg)
        {
            //send message to all but this one
            string broadcast = string.Format("[{0}] {1}\n", contex.Channel.RemoteAddress, msg);
            string response  = string.Format("[you] {0}\n", msg);

            group.WriteAndFlushAsync(broadcast, new EveryOneBut(contex.Channel.Id));
            contex.WriteAndFlushAsync(response);

            if (string.Equals("bye", msg, StringComparison.OrdinalIgnoreCase))
            {
                contex.CloseAsync();
            }
        }
Beispiel #5
0
        protected override void ChannelRead0(IChannelHandlerContext context, string message)
        {
            var clientMessage = $"[{context.Channel.RemoteAddress}] {message}\n";
            var serverMessage = $"[server] {message}\n";

            group.WriteAndFlushAsync(clientMessage, new EveryOneBut(context.Channel.Id));
            context.WriteAndFlushAsync(serverMessage);

            _logger.LogInformation(clientMessage);
            _logger.LogInformation(serverMessage);

            if (string.Equals(_server.Options.SecureChatServer.ExitCommand, message, StringComparison.OrdinalIgnoreCase))
            {
                context.CloseAsync();
                _logger.LogInformation(message);
            }
        }
Beispiel #6
0
        public override void ChannelActive(IChannelHandlerContext context)
        {
            IChannelGroup g = group;

            if (g == null)
            {
                lock (this)
                {
                    if (group == null)
                    {
                        g = group = new DefaultChannelGroup(context.Executor);
                    }
                }
            }

            g.WriteAndFlushAsync(string.Format("Welcome to {0} secure chat server!\n", Dns.GetHostName()));
            g.Add(context.Channel);
        }
        public override void ChannelRead(IChannelHandlerContext context, object message)
        {
            var byteBuffer = message as IByteBuffer;

            if (byteBuffer != null)
            {
                byte[] udpData = new byte[byteBuffer.ReadableBytes];
                byteBuffer.GetBytes(0, udpData);

                var decodedPacket = UDPVoicePacket.DecodeVoicePacket(udpData, false);

                SRClient srClient;
                if (_clientsList.TryGetValue(decodedPacket.Guid, out srClient))
                {
                    srClient.ClientChannelId = context.Channel.Id.AsShortText();

                    var spectatorAudioDisabled =
                        _serverSettings.GetGeneralSetting(ServerSettingsKeys.SPECTATORS_AUDIO_DISABLED).BoolValue;

                    if ((srClient.Coalition == 0) && spectatorAudioDisabled)
                    {
                        byteBuffer.Release();
                        return;
                    }
                    else
                    {
                        HashSet <string> matchingClients = new HashSet <string>();

                        for (int i = 0; i < decodedPacket.Frequencies.Length; i++)
                        {
                            // Magical ignore message 4 - just used for ping
                            if (decodedPacket.Modulations[0] == 4)
                            {
                                continue;
                            }

                            var coalitionSecurity =
                                _serverSettings.GetGeneralSetting(ServerSettingsKeys.COALITION_AUDIO_SECURITY).BoolValue;

                            foreach (KeyValuePair <string, SRClient> _client in _clientsList)
                            {
                                //dont send to receiver
                                if (_client.Value.ClientGuid != decodedPacket.Guid)
                                {
                                    //check frequencies
                                    if ((!coalitionSecurity || (_client.Value.Coalition == srClient.Coalition)))
                                    {
                                        var radioInfo = _client.Value.RadioInfo;

                                        if (radioInfo != null)
                                        {
                                            RadioReceivingState radioReceivingState = null;
                                            bool decryptable;
                                            var  receivingRadio = radioInfo.CanHearTransmission(decodedPacket.Frequencies[i],
                                                                                                (RadioInformation.Modulation)decodedPacket.Modulations[i],
                                                                                                decodedPacket.Encryptions[i],
                                                                                                decodedPacket.UnitId,
                                                                                                emptyBlockedRadios,
                                                                                                out radioReceivingState,
                                                                                                out decryptable);

                                            //only send if we can hear!
                                            if (receivingRadio != null && !matchingClients.Contains(_client.Value.ClientChannelId))
                                            {
                                                matchingClients.Add(_client.Value.ClientChannelId);
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        //send to other connected clients
                        if (matchingClients.Count > 0)
                        {
                            group.WriteAndFlushAsync(message, new AllMatchingChannels(matchingClients));
                        }
                        else
                        {
                            byteBuffer.Release();
                        }
                    }
                }
                else
                {
                    byteBuffer.Release();
                }
            }
        }
Beispiel #8
0
        public async Task <int> Broadcast(IByteBuffer byteBuffer)
        {
            await group.WriteAndFlushAsync(byteBuffer);

            return(group.Count);
        }
Beispiel #9
0
        public override void ChannelActive(IChannelHandlerContext contex)
        {
            IChannelGroup g = group;

            if (g == null)
            {
                lock (this)
                {
                    if (group == null)
                    {
                        g = group = new DefaultChannelGroup(contex.Executor);
                    }
                }
            }
            contex.WriteAndFlushAsync(string.Format("[SERVER] : Welcome to Uno Server !\n"));
            if (numberPlayer == 4)
            {
                contex.WriteAndFlushAsync("[SERVER] : Sorry, game already started.\n");
                contex.CloseAsync();
                return;
            }
            ClientUser tmp = new ClientUser(contex, numberPlayer + 1);

            listUser.Add(tmp);
            numberPlayer += 1;
            g.Add(contex.Channel);
            SendIdAndCard(contex);
            if (numberPlayer == 4)
            {
                SetPlayerStart();
            }
            else
            {
                group.WriteAndFlushAsync(string.Format("[SERVER] : Player {0} has join. {1} player left before game start !\n", numberPlayer, 4 - (numberPlayer)));
            }
        }