Пример #1
0
        private void HandleLog(int mode)
        {
            SQLiteClass sql = new SQLiteClass(ProgramFilesx86() + "\\DuckServer\\Information.dat");
            MSSQL       msl;

            if (!Service.shouldIBeRunning)
            {
                Console.WriteLine("This server instance should not be handling requests now.");
            }

            switch (mode)
            {
            case IM_Event:
                if (Service.shouldIBeRunning)
                {
                    String eventString = br.ReadString();
                    Events ev          = DeserializeXMLFileToObject <Events>(eventString);
                    sql.CloseCon();
                    msl = new MSSQL();
                    msl.AddEvent(ev);
                    bw.Write(IM_OK);
                }
                else
                {
                    bw.Write(IM_Bad_Credentials);
                }
                break;

            case IM_NewVersions:
                if (Service.shouldIBeRunning)
                {
                    IMClient imc = new IMClient();
                    imc.setConnParams(GetOriginIP(), 25567);
                    imc.SetupConn();
                    imc.SendSignal(IM_NewVersions, Service.DoSerialize(new DateTimeVersions {
                        ServiceVersion = sql.GetServices(), WhitelistVersion = sql.GetWhitelists(), ServiceDateTime = sql.GetLastUpdated(SQLiteClass.GET_SERVICE_LIST), WhitelistDateTime = sql.GetLastUpdated(SQLiteClass.GET_WHITELIST_LIST)
                    }));
                    bw.Write(IM_OK);
                }
                else
                {
                    bw.Write(IM_Bad_Credentials);
                }
                break;

            case IM_AddDatabases:
                sql.AddDatabase(new DatabaseObject(br.ReadString(), br.ReadInt32()));
                bw.Write(IM_OK);
                break;

            case IM_GetDatabases:
                List <DatabaseObject> dbos = sql.GetConnections();
                foreach (DatabaseObject dbo in dbos)
                {
                    bw.Write(dbo.ConnectionString);
                    bw.Write(dbo.Preference);
                }
                bw.Write(IM_OK);
                sql.CloseCon();
                break;

            case IM_NewDatabases:
                List <DatabaseObject> dbs = DeserializeXMLFileToObject <List <DatabaseObject> >(br.ReadString());
                sql.NewConnections(dbs);
                sql.CloseCon();
                break;

            case IM_NewServiceList:
                List <ServicesObject> sros = DeserializeXMLFileToObject <List <ServicesObject> >(br.ReadString());
                sql.NewServices(sros);
                sql.CloseCon();

                //Port scan
                //Broadcast
                break;

            case IM_NewWhitelists:
                List <Whitelists> wls = DeserializeXMLFileToObject <List <Whitelists> >(br.ReadString());
                sql.NewWhitelists(wls);
                sql.CloseCon();
                break;

            case IM_AddWhiteList:
                break;

            case IM_RemoveWhitelist:
                break;

            case IM_Debug:
                Console.WriteLine(br.ReadString());
                break;

            case IM_Diagnostic:
                if (!Service.shouldIBeRunning)
                {
                    bw.Write(IM_Bad_Credentials);
                }
                else
                {
                    bw.Write(IM_OK);
                }
                break;

            default:
                break;
            }
            bw.Write(IM_OK);
        }