Esempio n. 1
0
        public void Connect(bool onPublicIp)
        {
            IniReader ini = new IniReader();

            ini.parse("../../../../../bin/config.ini");

            Port = Convert.ToInt32(ini.get("Watch2Gether", "port"));

            Helper.Log("===== STREAMNIA - WATCH2GETHER SERVER =====\n");
            Helper.Log("Starte Server auf Port " + Port + "...");

            appServer   = new WebSocketServer();
            connections = new List <Connection>();

            //Setup the appServer
            if (!appServer.Setup(Port)) //Setup with listening port
            {
                Helper.Log("Server konte nicht auf Port " + Port + " eingerichtet werden.", ConsoleColor.Red);
                return;
            }

            appServer.NewMessageReceived  += new SessionHandler <WebSocketSession, string>(appServer_NewMessageReceived);
            appServer.NewSessionConnected += new SessionHandler <WebSocketSession>(appServer_NewSessionConnected);
            appServer.SessionClosed       += new SessionHandler <WebSocketSession, CloseReason>(appServer_SessionCLosed);

            //Try to start the appServer
            if (!appServer.Start())
            {
                Helper.Log("Server starten fehlgeschlagen!", ConsoleColor.Red);
                return;
            }
            else
            {
                //Setup MySQL
                Helper.Log("MySql Verbindung herstellen...");

                bool init = Sql.init(); //Connect allow from other IP: http://stackoverflow.com/a/3507278
                if (!init)
                {
                    Helper.Log("Error", ConsoleColor.Red, "Mysql konnte nicht initialisiert werden.");
                    Console.ReadKey();
                    return;
                }

                // User aus räumen löschen
                Sql.query("DELETE FROM rooms_users");

                Helper.Log("\n===== Setup erfolgreich! =====", true, ConsoleColor.Green);
                Helper.Log("\nDrücke ENTER um den Server zu beenden.");
            }
        }
Esempio n. 2
0
        public static bool init()
        {
            IniReader ini = new IniReader();

            ini.parse("../../../../../bin/config.ini");

            string server   = ini.get("Database", "host");
            string database = ini.get("Database", "db");
            string user     = ini.get("Database", "user");
            string password = ini.get("Database", "password");

            con = new MySqlConnection("SERVER=" + server + ";DATABASE=" + database + ";UID=" + user + ";PASSWORD="******";");

            return(OpenConnection());
        }