Example #1
0
        private static void DecodeCommand(string message)
        {
            var list     = message.Split(':');
            var commando = list[1].ToLower();

            if (commando == "quit")
            {
                StatusMessage("Exiting program...");
                running = false;
                return;
            }

            if (commando == "sethost")
            {
                remoteName = list[2];
                StatusMessage($"Setting target to {list[2]}");
            }
            else if (commando == "setname")
            {
                client.Name = list[2];
                StatusMessage($"Setting name to {list[2]}");
            }
            else if (commando == "cls")
            {
                window.Messages.Clear();
            }
            else if (commando == "connect")
            {
                if (client.Connect(remoteName, remotePort))
                {
                    StatusMessage("Starting receiving from server...");
                    client.StartReceiving((data) =>
                    {
                        try
                        {
                            while (!data.EOF)
                            {
                                string name        = data.GetString();
                                string messageData = data.GetString();

                                window.Add(new WebMessage(name, messageData));
                            }
                        }
                        catch (Exception e)
                        {
                        }
                    });
                }
                else
                {
                    StatusMessage("Connection failed...");
                }
            }
            else if (list[1] == "help")
            {
                ShowHelp();
            }
            else
            {
                StatusMessage($"Unknown command {list[1]}");
            }
        }