Esempio n. 1
0
        internal Command createLoginSuceedCommand(Authenticator smartAuthenticator)
        {
            byte[]  nothing  = new byte[] { 10, 10, 10, 10 };
            Command nCommand = CommandFactory.createCommand(smartAuthenticator.generateNewId(), "SERVER", 7, "none", "Login successed", nothing);

            return(nCommand);
        }
Esempio n. 2
0
        private Command getAvaibleFiles(Command cmd)
        {
            XmlManager    xmlManager   = new XmlManager();
            FileManager   fileManager  = new FileManager();
            List <string> allFilePaths = fileManager.listAllFilesInCategoryFolders(xmlManager.getAllChilds());

            Logger.print(allFilePaths.Count + "");
            //allFilePaths = sortFilesByCreationTime(allFilePaths);
            return(CommandFactory.createCommand(cmd.Id, SERVERNAME, SEND_AVAIBLE_FILES, "none", concatFiles(allFilePaths), new byte[1]));
        }
Esempio n. 3
0
        private Command getDataFromServer(Command cmd)
        {
            XmlManager xmlManager    = new XmlManager();
            Security   SmartSecurity = new Security();
            string     category      = cmd.Parameter;
            string     filename      = cmd.Filename;
            //TODO: IS FILE PATH ALLOWED?
            FileManager MyFileManager = new FileManager();

            byte[] data = MyFileManager.loadFile(category, filename);
            Logger.getDataFromServer();
            return(CommandFactory.createCommand(cmd.Id, SERVERNAME, SEND_DATA_TO_CLIENT, filename, category, data));
        }
Esempio n. 4
0
        private Command thumbnail(Command cmd)
        {
            CommandFactory cmdFactory    = new CommandFactory();
            Security       SmartSecurity = new Security();
            XmlManager     xmlManager    = new XmlManager();
            List <string>  allRootPaths  = xmlManager.getAllChilds();
            //TODO: IS IT A REAL IMAGE????
            Image          image     = Image.FromFile(cmd.Filename);
            Image          thumb     = image.GetThumbnailImage(120, 120, () => false, IntPtr.Zero);
            ImageConverter converter = new ImageConverter();

            byte[] imgArray = (byte[])converter.ConvertTo(thumb, typeof(byte[]));
            return(CommandFactory.createCommand(this.SmartAuthenticator.Id, SERVERNAME, SEND_CLIENT_THUMBNAIL, cmd.Filename, "none", imgArray));
        }
Esempio n. 5
0
        private Command saveDataOnServer(Command cmd)
        {
            XmlManager     xmlManager    = new XmlManager();
            List <string>  allRootPaths  = xmlManager.getAllChilds();
            string         category      = cmd.Parameter;
            string         filename      = cmd.Filename;
            FileManager    MyFileManager = new FileManager();
            CommandFactory cmdFactory    = new CommandFactory();

            //TODO: IS PATH FOR SAVING DATA ALLOWED? (NOT SOOO IMPORTANT)
            MyFileManager.saveFile(filename, cmd.Data);
            Logger.saveDataOnServer(cmd);
            return(CommandFactory.createCommand(cmd.Id, SERVERNAME, STATUS, filename, "saved file", new byte[1]));
        }
Esempio n. 6
0
        private Command deleteFileFromServer(Command cmd)
        {
            Security       SmartSecurity = new Security();
            XmlManager     xmlManager    = new XmlManager();
            List <string>  allRootPaths  = xmlManager.getAllChilds();
            CommandFactory cmdFactory    = new CommandFactory();
            //TODO: IS FILE PATH ALLOWED?
            //if (SmartSecurity.PathIsAllowed(allRootPaths,cmd.Filename))
            //{
            FileManager fileManager = new FileManager();

            fileManager.deleteFile(cmd.Filename);
            return(CommandFactory.createCommand(SmartAuthenticator.Id, SERVERNAME, STATUS, cmd.Filename, "deleted file", new byte[1]));
            //}
            //return CommandFactory.createCommand(SmartAuthenticator.Id, SERVERNAME, STATUS, cmd.Filename, "not deleted file", new byte[1]);
        }
Esempio n. 7
0
 private Command logout()
 {
     this.SmartKiller.hardKill();
     this.SmartAuthenticator.logout();
     return(CommandFactory.createCommand(-1, SERVERNAME, STATUS, "none", "OK", new byte[1]));
 }
Esempio n. 8
0
        private Command createErrorCommand()
        {
            Command cmd = CommandFactory.createCommand(-1, SERVERNAME, STATUS, "none", "undefined error", new byte[1]);

            return(cmd);
        }
Esempio n. 9
0
 internal void sendWrongId(Socket currentClient)
 {
     currentClient.Send(CommandFactory.createCommand(-1, "SERVER", 7, "none", WRONG_ID, new byte[1]).toByteArr(), SocketFlags.None);
 }
Esempio n. 10
0
 internal void sendLoginRequired(Socket currentClient)
 {
     currentClient.Send(CommandFactory.createCommand(-1, "SERVER", 7, "none", LOGIN_REQUIRED, new byte[1]).toByteArr(), SocketFlags.None);
 }
Esempio n. 11
0
 internal void sendObituary(Socket currentClient)
 {
     currentClient.Send(CommandFactory.createCommand(-1, "SERVER", 7, "none", KILLED_BY_KILLER, new byte[1]).toByteArr(), SocketFlags.None);
 }
Esempio n. 12
0
 internal void sendWrongCommandFormat(Socket currentClient)
 {
     currentClient.Send(CommandFactory.createCommand(-1, "SERVER", 7, "none", WRONG_COMMAND_FORMAT, new byte[1]).toByteArr(), SocketFlags.None);
 }
Esempio n. 13
0
 public void sendWrongPassword(Socket socket)
 {
     socket.Send(CommandFactory.createCommand(-1, "SERVER", 7, "none", WRONG_PASSWORD, new byte[1]).toByteArr(), SocketFlags.None);
 }