Ejemplo n.º 1
0
        public void WindowsToUtf8()
        {
            string   data     = "05ácido";
            Encoding encoding = Encoding.GetEncoding("ISO-8859-1");

            if (OsUtil.IsLinux())
            {
                encoding = Encoding.UTF8;
            }
            sbyte[]        buf    = data.GetSbytes(encoding);
            LlvarParseInfo parser = new LlvarParseInfo
            {
                Encoding = Encoding.Default
            };

            if (OsUtil.IsLinux())
            {
                parser.Encoding = Encoding.UTF8;
            }

            IsoValue field = parser.Parse(1, buf, 0, null);

            Assert.Equal(field.Value, data.Substring(2));
            parser.Encoding = encoding;
            field           = parser.Parse(1, buf, 0, null);
            Assert.Equal(data.Substring(2), field.Value);
        }
Ejemplo n.º 2
0
        // This method connects us to the server.
        // Winsock is very optimistic about connecting to the server.
        // It will not tell you, for instance, if the server actually accepted the connection.  It assumes that it did.
        public bool Connect(string cmdstring)
        {
            Exceptionthrown = false;

            if (!CreateSocket(cmdstring))
            {
                return(false);
            }
            try
            {
                var parameters = OsUtil.ParseParams(cmdstring);
                if (parameters.Count > 1)
                {
                    // This will succeed as long as some server is listening on this IP and port
                    var connectendpoint = CreateIpEndPoint(parameters[0], Convert.ToInt32(parameters[1]));
                    Connectionsocket.Connect(Connectionendpoint);
                    return(true);
                }
                Lasterror = "Server and Port not specified on client connection.";
                return(false);
            }
            catch (Exception ex)
            {
                Exceptionthrown = true;
                Lasterror       = ex.ToString();
                return(false);
            }
        }
Ejemplo n.º 3
0
        // This method is used to send a message to the server
        public bool Send(string cmdstring)
        {
            Exceptionthrown = false;

            var parameters = OsUtil.ParseParams(cmdstring);

            if (parameters.Count > 0)
            {
                try
                {
                    // We need a connection to the server to send a message
                    if (!Connectionsocket.Connected)
                    {
                        return(false);
                    }
                    var byData = Encoding.ASCII.GetBytes(parameters[0]);
                    Connectionsocket.Send(byData);
                    return(true);
                }
                catch (Exception ex)
                {
                    Lasterror = ex.ToString();
                    return(false);
                }
            }
            Lasterror = "No message provided for Send.";
            return(false);
        }
Ejemplo n.º 4
0
        public ConfirmPlayScreen(string fname, RemuxWindow wnd)
        {
            this.wnd = wnd;
            romPath  = fname;
            string fileSeparator = OsUtil.IsWindows() ? "\\" : "/";

            romName = fname.Substring(fname.LastIndexOf(fileSeparator));
        }
Ejemplo n.º 5
0
        private void EnterPressed()
        {
            if (pointerIndex < subDirectories.Count)
            {
                string chosenDir = subDirectories[pointerIndex];

                if (chosenDir == ".." && currentDirectory.Length > 3)
                {
                    bool flag = OsUtil.IsWindows() ? currentDirectory.LastIndexOf("\\") != 2 : currentDirectory != "/";
                    if (flag)
                    {
                        if (OsUtil.IsWindows())
                        {
                            currentDirectory = currentDirectory.Substring(0, currentDirectory.LastIndexOf("\\"));
                        }
                        else
                        {
                            currentDirectory = currentDirectory.Substring(0, currentDirectory.LastIndexOf("/"));
                            if (currentDirectory == "")
                            {
                                currentDirectory = "/";
                            }
                        }
                    }
                    else
                    {
                        currentDirectory = currentDirectory.Substring(0, 3);
                    }
                }
                else if (pointerIndex != 0)
                {
                    currentDirectory = subDirectories[pointerIndex];
                }
                RefreshDirectory();
            }
            else
            {
                string      fname = GetFileBrowserIndex(pointerIndex).Item1;
                RemuxWindow wnd   = (RemuxWindow)game;
                wnd.StateManager.TransitionTo(fname.EndsWith(".gb") ? (IState) new GameboyPlayScreen(fname, wnd) : new ConfirmPlayScreen(fname, wnd));
            }
        }
Ejemplo n.º 6
0
        private static void Main(string[] args)
        {
            //application state trackers
            var shutdown        = false;
            var serverstarted   = false;
            var clientconnected = false;

            _osUtil = new OsUtil();

            // This is a loop to get commands from the user and execute them
            while (!shutdown)
            {
                Console.Write("> ");
                var userinput = Console.ReadLine();

                if (!string.IsNullOrEmpty(userinput))
                {
                    switch (_osUtil.ParseCommand(userinput))
                    {
                    case OsUtil.OsCmd.OsExit:
                    {
                        if (serverstarted)
                        {
                            _osServer.Stop();
                        }
                        shutdown = true;
                        break;
                    }

                    case OsUtil.OsCmd.OsStartserver:
                    {
                        if (!serverstarted)
                        {
                            _osServer = new OsServer();
                            var started = _osServer.Start(userinput);
                            if (!started)
                            {
                                Console.WriteLine("Failed to Start Server.");
                                Console.WriteLine(_osServer.GetLastError());
                            }
                            else
                            {
                                Console.WriteLine("Server started successfully.");
                                serverstarted = true;
                            }
                        }
                        else
                        {
                            Console.WriteLine("Server is already running.");
                        }
                        break;
                    }

                    case OsUtil.OsCmd.OsConnect:
                    {
                        if (!clientconnected)
                        {
                            _osClient = new OsClient();
                            var connected = _osClient.Connect(userinput);
                            if (!connected)
                            {
                                Console.WriteLine("Failed to connect Client.");
                                Console.WriteLine(_osClient.GetLastError());
                            }
                            else
                            {
                                Console.WriteLine("Client might be connected.  It's hard to say.");
                                clientconnected = true;
                            }
                        }
                        else
                        {
                            Console.WriteLine("Client is already connected");
                        }
                        break;
                    }

                    case OsUtil.OsCmd.OsDisconnect:
                        if (clientconnected)
                        {
                            _osClient.DisConnect();
                            clientconnected = false;
                            Console.WriteLine("Client dis-connected from server successfully.");
                        }
                        break;

                    case OsUtil.OsCmd.OsSend:
                    {
                        if (clientconnected)
                        {
                            _osClient.Send(userinput);
                            Console.WriteLine("Message sent from client...");
                        }
                        else
                        {
                            Console.WriteLine("Send Failed with message:");
                            Console.WriteLine(_osClient.GetLastError());
                        }
                        break;
                    }

                    case OsUtil.OsCmd.OsHelp:
                    {
                        Console.WriteLine("Available Commands:");
                        Console.WriteLine("startserver <port> = Start the OS Server (Limit 1 per box)");
                        Console.WriteLine("connect <server> <port> = Connect the client to the OS Server");
                        Console.WriteLine("disconnect = Disconnect from the OS Server");
                        Console.WriteLine("send <message> = Send a message to the OS Server");
                        Console.WriteLine("exit = Stop the server and quit the program");
                        break;
                    }
                    }
                }
            }
        }