Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            bstuff = new BotStuff();
            Donify = bstuff.OnyVariables.Donify;
            logger = bstuff.OnyVariables.logger;
            nstruct = bstuff.OnyVariables.nstruct;
            if (!File.Exists("funcpersistence.xml"))
                bstuff.OnyVariables.persistence.save();
            bstuff.OnyVariables.persistence.load();
            LoadPlugins();
            bstuff.OnyEvents.InComingMessage += new BotStuff.BotEvents.IncomingMessageHook(OnyEvents_InComingMessage);
            if (!socketfunctions.trybindsocket(mainsock, ref port, true, 50, IPAddress.Any))
            { logger.log("FAILED TO BIND TO ANY PORT. EXITTING", Logging.Priority.Critical); return; }
            logger.log("Initialized main function", Logging.Priority.Info);
            logger.log("Loading variables..",Logging.Priority.Notice);

            try
            { bstuff.OnyFunctions.PrivFunctions.loadnow(new OnyLib.SpecialClasses.BotFunctionData(nstruct)); }
            catch (Exception ex)
            { logger.logerror(ex); }
            logger.log("Trying to load playback file..", Logging.Priority.Notice);
            try { nstruct.loadplayback(); }
            catch (Exception ex) { logger.logerror(ex); }

            while (bstuff.OnyVariables.run)
            {
                if ((bstuff.OnyVariables.amountloops % 10) == 0) { nstruct.saveplayback(); bstuff.OnyVariables.amountloops = 0; bstuff.OnyVariables.persistence.save(); }
                logger.log("Waiting for incoming commands", Logging.Priority.Info);
                Donify.Reset();
                mainsock.BeginAccept(new AsyncCallback(acceptIncomingConnection), mainsock);
                Donify.WaitOne();
            }
            nstruct.saveplayback();
            bstuff.OnyVariables.persistence.save();
            Console.WriteLine("Going down!");
            logger.log("Shutting down bot.", Logging.Priority.Notice);
            logger.log("Uptime: " + (DateTime.Now - bstuff.OnyVariables.starttime).ToString(), Logging.Priority.Info);
            Environment.Exit(0);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            formConsole mainconsole = new formConsole();
            mainconsole.Show();

            CedLib.Errorhandling errorhandler = new CedLib.Errorhandling("CEDLIB TESTER mainconsole 1.0)", true, true);
            CedLib.Logging logger = new CedLib.Logging(true, true);
            mainconsole.WriteLine("Main program writeline");
            logger.log("This is a test log entry", CedLib.Logging.Priority.Notice);
            logger.logerror(new Exception("This is a test exception to test the logerror class"));

            mainconsole.WriteLine("End for testing errorhandling and logging.\n\n==============\nCommencing testing for networking.\n");

            int serverport = 5000;
            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.ReuseAddress, true);

            if (!CedLib.Networking.socketfunctions.trybindsocket(sock, ref serverport, mainconsole, 50, IPAddress.Any))
            { mainconsole.WriteLine(string.Format("Failed to bind to port {0}!", serverport)); }
            Thread t = new Thread(new ParameterizedThreadStart(SocketServer));
            t.Start(sock);
            Thread.Sleep(1);
            Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            client.Connect(IPAddress.Loopback, serverport);
            CedLib.Networking.socketfunctions.sendstring(client, "Ping!");
            CedLib.Networking.socketfunctions.waitfordata(client, 10000, mainconsole);
            mainconsole.WriteLine(string.Format("Send 'Ping!', got back: {0}", CedLib.Networking.socketfunctions.receivestring(client, false)));
            mainconsole.WriteLine("Commencing filetransfer test");
            CedLib.Networking.socketfunctions.sendfile(client, new System.IO.FileInfo("input.kaas"), mainconsole);

            mainconsole.WriteLine("-------------------------");
            mainconsole.WriteLine("Commencing byte transfer test");
            CedLib.Globals.chunksize = 65536;
            mainconsole.WriteLine("Set chunksize to " + CedLib.Globals.chunksize);
            client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            client.Connect(IPAddress.Loopback, serverport);
            CedLib.Networking.socketfunctions.sendstring(client, "kaas");
            CedLib.Networking.socketfunctions.waitfordata(client, 30000, mainconsole);
            CedLib.Networking.CedLibContentheader cHeader = CedLib.Networking.socketfunctions.ParseContentHeader(CedLib.Networking.socketfunctions.receivestring(client,mainconsole));
            System.IO.MemoryStream memstream = CedLib.Networking.socketfunctions.receivebytes(client, cHeader, mainconsole);
            misc_usefulfunctions.picform pictureform = new misc_usefulfunctions.picform(memstream);
            pictureform.ShowDialog();

            Console.WriteLine("--------------------");
            Console.WriteLine("Commencing XML persistency test");
            CedLib.Persistence.XMLPersistenceDictionary.XMLPersistenceDictionary persistence = new CedLib.Persistence.XMLPersistenceDictionary.XMLPersistenceDictionary(logger); //Works!!
            persistence.Add("test", "testvaluefennecs");
            persistence["test"].Add("test", "fennecs");
            if (!persistence.ContainsKey("test"))
                throw new Exception("XML test failed! Dictionary did not properly detect present key!");
            if(persistence.ContainsKey("fennecs"))
                throw new Exception("XML test failed! Dictionary did not properly detect nonpresent key!");
            if (!persistence.ContainsValue("testvaluefennecs"))
                throw new Exception("XML test failed! Dictionary did not properly detect present value!");
            if(persistence.ContainsValue("test"))
                throw new Exception("XML test failed! Dictionary did not properly detect nonpresent value!");
            Console.WriteLine(persistence["test"].obj);
            foreach (var snode in persistence)
            {
                Console.Write("Contents: " + snode.obj);
                foreach (var item in snode.childnodes)
                {
                    Console.Write("Contents: " + item.obj);
                }
            }
            Console.WriteLine("\nSaving dictionary");
            persistence.save("test.xml");
            persistence = null; Console.WriteLine("Nullified dictionary");
            persistence = new CedLib.Persistence.XMLPersistenceDictionary.XMLPersistenceDictionary();
            persistence.load("test.xml");
            Console.WriteLine("Loaded dictionary");
            if (persistence["test"].obj != "testvaluefennecs")
            {
                logger.logerror(new Exception("XML test failed!! Expected 'testvaluefennecs', got: " + persistence["test"].obj));
            }
            else
                Console.WriteLine("XML test success!");
        }