Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.Title           = "EllApp WebSocket Server";
            Console.WriteLine("Running EllApp Socket Server ...");
            Console.WriteLine("[Type \"exit\" and hit enter to stop the server]");

            if (Configuration != null)
            {
                // Start the server
                socketThread = new Thread(new ThreadStart(StartSocketServer));
                socketThread.Start();

                string content = "";
                while (content != null && content != "exit")
                {
                    if (content != "")
                    {
                        CommandHandlers cmd    = new CommandHandlers();
                        Type            type   = cmd.GetType();
                        MethodInfo      metodo = type.GetMethod(Utility.ToTitleCase(content));
                        switch (content)
                        {
                        case "fakemessage":
                        case "gsm":
                        case "online":
                            metodo.Invoke(cmd, new object[] { Server.Sessions });
                            break;

                        case "serverinfo":
                            metodo.Invoke(cmd, new object[] { Server });
                            break;

                        case "commands":
                            metodo.Invoke(cmd, null);
                            break;

                        case "createaccount":
                        case "clearconsole":
                            break;

                        default:
                            logger.Warn($"Unknown command \"{content}\".");
                            break;
                        }
                    }
                    content = Console.ReadLine();
                }
            }
            else
            {
                Console.WriteLine("No configuration file found. Exit in 5 seconds..");
                Thread.Sleep(5 * 1000);
                Environment.Exit(0);
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            // instantiate a new server - acceptable port and IP range,
            // and set up your methods.

            aServer = new WebSocketServer(Convert.ToInt16(ConfigurationSettings.AppSettings["serverport"]), System.Net.IPAddress.Any)
            {
                OnReceive    = OnReceive,
                OnSend       = OnSend,
                OnConnected  = OnConnect,
                OnDisconnect = OnDisconnect,
                TimeOut      = new TimeSpan(0, 5, 0)
            };
            aServer.Start();


            Console.ForegroundColor = ConsoleColor.Red;
            Console.Title           = "EllApp WebSocket Server";
            Console.WriteLine("Running EllApp WebSocket Server ...");
            Console.WriteLine("[Type \"exit\" and hit enter to stop the server]");

            //Open DB Instance
            DB.Instantiate();

            // Accept commands on the console and keep it alive
            var command = string.Empty;

            while (command != "exit")
            {
                if (command != "")
                {
                    CommandHandlers cmd    = new CommandHandlers();
                    Type            type   = cmd.GetType();
                    MethodInfo      metodo = type.GetMethod(Utility.ToTitleCase(command));
                    switch (command)
                    {
                    case "fakemessage":
                    case "gsm":
                    case "online":
                        metodo.Invoke(cmd, new object[] { Sessions });
                        break;

                    case "serverinfo":
                        metodo.Invoke(cmd, new object[] { aServer });
                        break;

                    case "commands":
                        metodo.Invoke(cmd, null);
                        break;

                    case "createaccount":
                    case "clearconsole":
                        break;

                    default:
                        logger.Warn($"Unknown command \"{command}\".");
                        break;
                    }
                }
                command = Console.ReadLine();
            }

            aServer.Stop();
            Environment.Exit(0);
        }