Example #1
0
        private void InitializeComponents()
        {
            callbacks      = new ConcurrentQueue <Action>();
            officers       = new StorageManager <Officer>();
            assignments    = new List <Assignment>();
            ofcAssignments = new Dictionary <Officer, Assignment>();
            commands       = new Dictionary <string, CommandAttribute>();
            bolos          = new StorageManager <Bolo>();
            civs           = new StorageManager <Civilian>();
            civVehs        = new StorageManager <CivilianVeh>();
            currentCalls   = new List <EmergencyCall>();

            cfg = new iniconfig(Function.Call <string>(Hash.GET_CURRENT_RESOURCE_NAME), "settings.ini");

            Permissions.SetInformation("permissions.perms", Function.Call <string>(Hash.GET_CURRENT_RESOURCE_NAME));
            perms = Permissions.Get;
            perms.Refresh();

            if (cfg.GetIntValue("server", "enable", 0) == 1)
            {
                ThreadPool.QueueUserWorkItem(x => server = new DispatchServer(cfg), null);
                Log.WriteLine("Starting DISPATCH server");
            }
            else
            {
                Log.WriteLine("Not starting DISPATCH server");
            }
            if (cfg.GetIntValue("database", "enable", 0) == 1)
            {
                Log.WriteLine("Reading database...");
                data    = new Database();
                civs    = data.Read <Civilian>("dsciv.db") ?? new StorageManager <Civilian>();
                civVehs = data.Read <CivilianVeh>("dsveh.db") ?? new StorageManager <CivilianVeh>();
                Log.WriteLine("Read and set database");

                ThreadPool.QueueUserWorkItem(async x =>
                {
                    await Delay(15000);
                    while (true)
                    {
#if DEBUG
                        Log.WriteLine("Writing current information to database");
#else
                        Log.WriteLineSilent("Writing current information to database");
#endif
                        data.Write(civs, "dsciv.db");
                        data.Write(civVehs, "dsveh.db");
                        await Delay(180 * 1000);
                    }
                });
            }
            else
            {
                Log.WriteLine("Not start database");
            }
        }
Example #2
0
        private static bool StartServers()
        {
            Console.Write("Loading User Database...");

            //String path = @"C:\Documents and Settings\David\My Documents\Visual Studio Projects\W3b.MsnpServer\Data\PinkEgoBox.sqlite";
            //String path = @"D:\Users\David\My Documents\Visual Studio Projects\Solutions\W3b.MsnpServer\Data\PinkEgoBox.sqlite";
            _dbPath = UtilityMethods.FindFile(new DirectoryInfo(Environment.CurrentDirectory), "PinkEgoBox.sqlite", 5);
            if (_dbPath == null)
            {
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Unable to locate database file");
                Console.ResetColor();
                return(false);
            }

            User.LoadDatabase(_dbPath);

            Console.WriteLine("Done");

            Console.WriteLine("Starting Servers...");

            _dispatchServer = DispatchServer.Instance;
            _dispatchServer.Start();

            Console.ForegroundColor = _dispatchServer.ConsoleColor;
            Console.WriteLine("Dispatch Server started, listening on " + _dispatchServer.EndPoint.ToString2());

            //////////////////////

            _notificationServer = NotificationServer.Instance;
            _notificationServer.Start();

            Console.ForegroundColor = _notificationServer.ConsoleColor;
            Console.WriteLine("Notification Server started, listening on " + _notificationServer.EndPoint.ToString2());

            //////////////////////

            _switchboardServer = SwitchboardServer.Instance;
            _switchboardServer.Start();

            Console.ForegroundColor = _switchboardServer.ConsoleColor;
            Console.WriteLine("Switchboard Server started, listening on " + _switchboardServer.EndPoint.ToString2());
            Console.ResetColor();

            return(true);
        }
Example #3
0
 protected DispatchProtocol(String name, int pref, DispatchServer server) : base(name, pref)
 {
     Server = server;
 }
Example #4
0
        private static void InitializeComponents()
        {
            // creating new instances of objects
            callbacks      = new ConcurrentQueue <Action>();
            Officers       = new StorageManager <Officer>();
            Assignments    = new StorageManager <Assignment>();
            OfcAssignments = new Dictionary <Officer, Assignment>();
            Bolos          = new StorageManager <Bolo>();
            Civs           = new StorageManager <Civilian>();
            CivVehs        = new StorageManager <CivilianVeh>();
            CurrentCalls   = new StorageManager <EmergencyCall>();
            Cfg            = new ServerConfig(Function.Call <string>(Hash.GET_CURRENT_RESOURCE_NAME), "settings.ini");

            // creating the permissions singleton
            Log.WriteLine("Setting permission information");
            Permissions.SetInformation(Function.Call <string>(Hash.LOAD_RESOURCE_FILE, Function.Call <string>(Hash.GET_CURRENT_RESOURCE_NAME), "permissions.perms"));
            Log.WriteLine("Parsing permission information");
            Perms = Permissions.Get;
            Log.WriteLine("Permissions set!");

            // reading config, then starting the server is config true
            if (Cfg.GetIntValue("server", "enable", 0) == 1)
            {
                ThreadPool.QueueUserWorkItem(x => Server = new DispatchServer(Cfg), null);
                Log.WriteLine("Starting DISPATCH server");
            }
            else
            {
                Log.WriteLine("Not starting DISPATCH server");
            }

            // reading config, then starting database if config true
            if (Cfg.GetIntValue("database", "enable", 0) == 1)
            {
                // starting the read/write thread for database
                async void RunDatabase()
                {
                    Log.WriteLine("Reading database...");
                    Data = new Database("dispatchsystem.data"); // creating the database instance
                    Tuple <StorageManager <Civilian>, StorageManager <CivilianVeh> > read;

                    try
                    {
                        read = Data.Read(); // reading the serialized tuple from the database
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine("----------------------------------------\n" +
                                        "     Error reading the data file\n" +
                                        "   More information in the log file\n" +
                                        "----------------------------------------");
                        Log.WriteLineSilent(e.ToString());
                        try
                        {
                            Data.Write(null);
                        }
                        catch (Exception e2)
                        {
                            Debug.WriteLine("-------------------------------------------\n" +
                                            "     Error writing the data file\n" +
                                            "    Is this a read/write problem?\n" +
                                            "   Stopping database functionality\n" +
                                            "   More information in the log file\n" +
                                            "-------------------------------------------");
                            Log.WriteLineSilent(e2.ToString());
                            return;
                        }
                        read = new Tuple <StorageManager <Civilian>, StorageManager <CivilianVeh> >(null, null);
                    }
                    Civs    = read?.Item1 ?? new StorageManager <Civilian>();
                    CivVehs = read?.Item2 ?? new StorageManager <CivilianVeh>();
                    Log.WriteLine("Read and set database"); // logging done

                    // starting while loop for writing the database
                    while (true)
                    {
#if DEBUG
                        Log.WriteLine("Writing current information to database");
#else
                        Log.WriteLineSilent("Writing current information to database");
#endif
                        // creating the tuple to write
                        var write = new Tuple <StorageManager <Civilian>, StorageManager <CivilianVeh> >(Civs, CivVehs);
                        // writing the information
                        Data.Write(write);
                        // waiting 3 minutes before doing it again
                        await Delay(180 * 1000);
                    }
                }

                new Thread(RunDatabase)
                {
                    Name = "Database Thread"
                }.Start();                                                   // starting database thread
            }
            else
            {
                Log.WriteLine("Not starting the database");
            }
        }
Example #5
0
 protected Cvr0DispatchProtocol(String name, int pref, DispatchServer server) : base(name, pref, server)
 {
 }
Example #6
0
 public Cvr0DispatchProtocol(DispatchServer server) : base("CVR0", 0, server)
 {
 }
 public Msnp2DispatchProtocol(DispatchServer server) : base("MSNP2", 2, server)
 {
 }
Example #8
0
 public Msnp3DispatchProtocol(DispatchServer server) : base("MSNP3", 3, server)
 {
 }
Example #9
0
 public Msnp4DispatchProtocol(DispatchServer server) : base("MSNP4", 4, server)
 {
 }