예제 #1
0
        private void InitializeTcpClient()
        {
            var callback = new ChatCallback
            {
                OnConnected = () =>
                              Dispatcher.Invoke(() => PrintMessage("Pomyślnie połączono z " + IpAddress + ":" + Port)),
                OnMessageReceived = message => Dispatcher.Invoke(() =>
                {
                    var format = MessageExtractor.Extract(message);
                    if (format == string.Empty)
                    {
                        return;
                    }

                    var msg = InformationConverter.Deserialize(format);
                    if (mutedUsers.Contains(msg.Nick))
                    {
                        return;
                    }

                    switch (msg.Type)
                    {
                    case InformationType.Message:
                        PrintUserLine(msg.Nick, msg.Message);
                        break;

                    case InformationType.Voice:
                        {
                            if (!UsersSpeakingTextBlock.Text.Contains(msg.Nick))
                            {
                                UsersSpeakingTextBlock.Text += "\uD83D\uDD0A" + msg.Nick + Environment.NewLine;
                            }
                            var byteMessage = Convert.FromBase64String(msg.Message);
                            _audioManager.Play(byteMessage);
                            break;
                        }

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }),
                OnDisconnected = () => Dispatcher.Invoke(() =>
                {
                    _client.Disconnect();
                    Environment.Exit(0);
                }),
                OnCannotConnect = () => Dispatcher.Invoke(() =>
                {
                    var formattedMessage = new ColoredMessageBuilder()
                                           .With("Nie można połączyć się z serwerem. Sprawdź dane połączenia.")
                                           .Build();
                    ChatBlock.Document.Blocks.Add(formattedMessage);
                    ShowConnectionDialog();
                    ConnectToServer();
                })
            };

            _client = new TCPClient(callback);
            ConnectToServer();
        }
예제 #2
0
        public void Run(ChatCallback Callback, List <string> Args)
        {
            if (Args.Count == 0)
            {
                this.UsageError(Callback, "Укажите название команды, которую хотите выбрать");
                return;
            }

            var TeamName = Args[0];
            var Team     = TeamsController.GetByName(TeamName);

            if (Team == null)
            {
                this.UsageError(Callback, $"Команда {TeamName} не найдена!");
                return;
            }

            var Whom = LanguageManager.Get($"m.team.{TeamName}.whom");

            if (!Team.Enable)
            {
                Callback.Send($"К сожалению, команда {Whom} выключена");
                return;
            }

            Callback.Send($"Вы успешно привязаны к команде {Whom}!");

            TeamAffinityController.PreSetAffinity(Team);
        }
예제 #3
0
        private static void InitializeTcpServer(int portNumber)
        {
            var callback = new ChatCallback
            {
                OnClientConnected = endPoint =>
                {
                    Console.WriteLine("Nowy klient połączony: {0}:{1}", endPoint.Address, endPoint.Port);
                },
                OnMessageReceived = (tcpUser, message) =>
                {
                    var endPoint         = (IPEndPoint)tcpUser.Socket.RemoteEndPoint;
                    var formattedMessage = MessageExtractor.Extract(message);
                    var information      = InformationConverter.Deserialize(formattedMessage);
                    if (information?.Type == Message)
                    {
                        Console.WriteLine(
                            $"{information.Nick} ({endPoint.Address}:{endPoint.Port}) : {information.Message}");
                    }
                },
                OnClientDisconnected = endPoint =>
                {
                    Console.WriteLine($"({endPoint.Address}:{endPoint.Port}) has disconnected!");
                }
            };
            var server = new TCPServer(portNumber, callback);

            server.Initialize();
        }
예제 #4
0
        public void Run(ChatCallback Callback, List <string> Args)
        {
            var Player = PlayerControl.LocalPlayer;

            ExtraNetwork.Send(CustomRPC.DebugVictory, Writer => {
                Writer.Write(Player.PlayerId);
            });

            DebugTools.DebugWin(Player);
        }
예제 #5
0
 public void Run(ChatCallback Callback, List <string> Args)
 {
     if (Args.Count == 0)
     {
         CommandsController.Help(Callback);
     }
     else
     {
         CommandsController.Help(Callback, Args[0]);
     }
 }
예제 #6
0
 public void Run(ChatCallback Callback, List <string> Args)
 {
     DebugTools.DebugWin(PlayerControl.LocalPlayer);
 }