예제 #1
0
 public static String[] UserAction(String[] commands)
 {
     ArrayList returnValues = new ArrayList();
     String[] value = null;
     Database database = new Database("users");
     database.read();
     if (commands[0].Equals(usrHead))
     {
         if(commands[1].Equals("ALL"))
         {
             Debug.Print("Getting User List");
             returnValues = database.getAll();
             value = new String[2];
             value[0] = "USER";
             for (int i = 0; i < 1; i++)
             {
                 Debug.Print("Found user " + ((ArrayList)(returnValues[i]))[0].ToString());
                 value[i + 1] = ((ArrayList)(returnValues[i]))[0].ToString();
             }
         }
         else if (commands[1].Equals("INFO"))
         {
             Debug.Print("Getting user information for user " + commands[2]);
             returnValues = database.get("username", commands[2]);
             if (returnValues.Count == 0)
             {
                 Debug.Print("Unable to find the desired user");
                 return null;
             }
             value = new String[((ArrayList)returnValues[0]).Count+1];
             value[0] = "URETURN";
             for(int i = 0;i < ((ArrayList)returnValues[0]).Count;i++)
                 value[i + 1] = ((ArrayList)(returnValues[0]))[i].ToString();
         }
         else if (commands[1].Equals("CHANGE"))
         {
             String username = commands[2];
             String password = commands[3];
             String admin = commands[4];
             Debug.Print(username + " " + password + " " + admin);
             returnValues = database.get("username", username);
             if (returnValues.Count == 0)
             {
                 ArrayList temp2 = new ArrayList();
                 temp2.Add(username);
                 String encrypted = SHA.encryptPassword(System.Text.Encoding.UTF8.GetBytes(password + "\0"));
                 temp2.Add(encrypted);
                 temp2.Add(admin);
                 database.add(temp2);
             }
             else
             {
                 ArrayList temp2 = ((ArrayList)(returnValues[0]));
                 if (password != "null")
                 {
                     String encrypted = SHA.encryptPassword(System.Text.Encoding.UTF8.GetBytes(password + "\0"));
                     temp2[1] = encrypted;
                 }
                 temp2[2] = admin;
                 database.modify(database.getIndex("username", username), temp2);
                 value = null;
             }
         }
     }
     return value;
 }
예제 #2
0
        public static void Main()
        {
            Debug.Print("Start...");
            ServerSocket.listen(8877);

            DatabaseGenerator.generateUsers();
            DatabaseGenerator.generateLogs();

            Encryption.init();
            Encryption.RSAgenerateKeys();
            Debug.Print(Encryption.toString());

            Debug.Print("Generated...");

            Database tempDatabase = new Database("users");
            tempDatabase.read();
            ArrayList temp2 = new ArrayList();
            temp2.Add("IC");
            String test = SHA.encryptPassword(System.Text.Encoding.UTF8.GetBytes("123\0"));
            //Debug.Print(SHA.byteToString(test));
            temp2.Add(test);
            temp2.Add("false");
            tempDatabase.add(temp2);

            while (true)
            {
                ArrayList cons = ServerSocket.getConnectionIDs();
                foreach (Object con in cons)
                {
                    if ((int)con != -1)
                    {
                        String temp;
                        while ((temp = ServerSocket.getNextMessage((int)con)) != null)
                            ServerSocket.sendMessage(-1, temp);
                    }
                }
            }

            while (true)
            {
            }

            /*
            Database tempDatabase = new Database("users");
            tempDatabase.read();
            ArrayList temp2 = new ArrayList();
            temp2.Add("IC");
            String test = SHA.encryptPassword(System.Text.Encoding.UTF8.GetBytes("123\0"));
            //Debug.Print(SHA.byteToString(test));
            temp2.Add(test);
            temp2.Add("false");
            temp2.Add("1");
            temp2.Add("2");
            tempDatabase.add(temp2);
            ArrayList tempData = tempDatabase.get("username", "IC");
            if (tempData.Count > 0)
                Debug.Print((String)tempData[0]);
            else
                Debug.Print("Unable to find any account");
             */
        }