Wednesday, 25 May 2011

Introduction to Second LIfe


Introduction


This week, we start out on something completely different from what we have done so far in this topic. After going through so many different Web technologies such as HTML, CSS, JavaScript and PHP we will now begin a few weeks working on Second Life.

Second Life is an online virtual world developed by Linden Lab launched in 2003, This is like a social networking website but instead of profiles people communicate with each other with the use of avatars. An avatar is a graphical representation of the user’s character. This is similar to many Multiplayer Online RPGs (Role-Playing Games) where a user has his own personalized avatar, meets with other people’s avatars on the network and then do stuff together.


What is different in Second Life then other Online Games and Networks is the ability to build stuff in the virtual world and then program it in any way you want. This could be anything from clothing to buildings to cars with each having its own individual use.



Installing and Logging In

To install the client program for Second life an account was created with Second life on the website creating a username and password with the username being used as the name of your avatar and a sample Avatar is chosen to start with which then could be fully customized to the users desires (except the username). After registering the client application is downloaded and installed.


After installing the application, one could log in by using the username and password chosen in the registration. Also you must chose to login in either Basic or Advanced Mode. The difference is that in Advance mode you could code using Linden Scripting Language and the menus are arraigned in a slightly different way. What I found to be quite puzzling is that before you log in if you change from Basic to Advance Mode or vice versa you have to close the application and restart it. Since at first I decided that I will just look a bit around to see how things work in Second Life I decided to run in Basic Mode.


What I found to be quite annoying in Second life is the massive loading time it took to load everyone’s Avatar and the terrain around you and I am using a laptop which I can run games which came out a month ago smoothly so I can only imagine in 2003 how much worse the loading times where at that time since the hardware wasn’t as good. When I saw this I decided to lower the graphics used as much as possible so that it will run smoothly but for some reason I could not find the edit menu item anywhere to change the graphics (see screenshot below) at least I found a shortcut to go to the preferences (ctrl + p) and I lowered the graphics. Although the application now was much smoother when walking around the loading times where still long to load everyone’s Avatar and the terrain when either logging in or teleporting to a new locations.


The World of Second Life

Apart from this when logging in the first time you will be taken to a place to learn the controls. I found that the hotkeys/shortcuts automatically set for the controls are much simpler to use then the actual controls detailed in this part by Second Life. For Example, the key that is used to fly (yes you can fly around in Second life) is told to be “Page Up” and to go back down to the ground is “Page Down”, while the hotkeys for this command is “e” and “c”. Also the same applies for moving, I much prefer the  WASD set up of the hotkeys then the arrow keys since the mouse is used a lot in this to click objects and interact with them.



Teleporting




Since I mentioned teleporting before, let me expand on that a bit.


In Second life you have a search where you can find your friends and add them to your friends list by sending them a request. Once this is done and the request is accepted you could have private chats with anyone in your friends list and also something which is helpful is that you could ask for a teleport to go near friends quickly instead of needing to chat and decide on a specific place to meet and then make sure it’s a place where your fiend will see your avatar.


Conclusion

To conclude this post, I decided to get a change of clothes so that I won’t look like a complete beginner. I right clicked my character and selected edit appearance and started messing around with the shape and clothes of my avatar. I changed his hair, his figure through the multiple menus and features and decided on a short and fat dwarf like shape with a big beard since all the general male avatar seemed tall and well built and I like to be different. Next week we’ll start building some objects and scripting



















Wednesday, 4 May 2011

CourseWork 2 Web space management system

Introduction

This blog post will detail how the coursework of the webspace management system was created and explaining all of its features. The system will consist of 3 main pages: the login page, the mainpage and a registration screen.

Here is the explaination given to us on what we should do.


Coursework Task

Write a remote Web space management system suitable for handling Web site content of various types. It should allow a user to add and organise files to a personal Web area which is secured by password. Again, there will be a connected theme, to be announced in lecture time.

This program should include the following features.


1)  Your program should be written as PHP scripts . The user should be able to work with this program via a Web browser from any computer connected to the Internet.

    2)  When your program starts, it should ask the user to enter a password and username, and not allow the user to access their Web space unless they know the password. Passwords should be stored in an appropriate MySQL database.
   
    3)  Once allowed access the user should be able to:
    a)  Make and delete directories
    b)  Delete files 
    c)  Upload new files
    d)  Only be able to access their own space, which should have space limits imposed upon it.

User data and passwords should be stored in an appropriate MySQL database or file system which the PHP script can access; you must consider security implications. There are no restrictions on the style of the user interface, although you should consider ease of use and design to be issues too.



Login Page

I started off with building on the login screen created in last week’s PHP with MySQL blog post. The main improvement on the Login Screen was that an extra button was created called Register which will be used to redirect the user to the registration screen. I also gave the login screen a bit of a space theme although I am no designer this is the best I could come up with.



Apart from this new button the login form has still basically the same functionality as before using cookies for the “remember me” function  for automated logins and using sessions to remember the username when the user is redirected to the mainpage so that only his page is viewed.


Registration Screen

This page consists of three textfields in which the user will fill in the Username desired to register and the password for the user. The 3rd textfield will be used as a confirm password as most registration form are. Again the Space theme was kept throughout for consistency.

  

When the user has filled in all the fields the user will press the register button which will first check if all the fields are filled in, then it will check if the password and confirm password match. If they do, an SQL connect is created with the localhost server and an SQL query is sent to the server to find out if the username chosen by the user already exists. This is done by selecting all the rows from the Users table where the Username is the username inserted by the user.  If the result of the query has a row it means that the username already exists.

  
If the Username doesn’t exist the username and password chosen are inserted in the table using the “mysql_query”. After the record is inserted the program will try to create a folder on the Server with the username as the folder name. This folder will be used as the folder loaded in the mainpage when this new user is created. If the folder is created a Session is created detailing that the registration is successful and the user is redirected to the login page.

  

The login page is checking for a session called Successful which is only created when a registration is successful, if its value is “Yes” an alert box is shown to let the user know that the Registration was successful. This was done in this way since if the alert box is created in the registration page, it is not shown due to the page is redirected to the login page, even if the alertbox is before the redirecting in the coding.




MainPage

When this page is loaded a check for a session named Username is done to write the Welcome + username. On the page, Also the session is used to open the folder using the “opendir” function in Php, the folder where the user will upload all his files since when this is created the name of the folder is the username chosen by the user. If the session is not found, the page is redirected back to the login.




This page consist of a file input with a button to start the event, a textbox with a button to add a folder with the name inserted in the textbox, a button to go back to the previous directory if you accessed a folder inside your personal space, a logout button to go back to the login screen, and a list of all the files and folders inside the space of the user name with a delete button near each one to be able to delete it. Here is a detailed explanation of each feature in the main page and how it was achieved using PHP.


The feature to load the files and folders of the user is achieved by using the “is_dir” feature to know if the item loaded is a folder or a file. If it’s a folder instead of just showing just showing the name of the file, the name of the folder would be a hyper link that would call a function to show all the files inside that particular folder by sending the name of the folder and adding it to the path used to get all the files from.


  
To know which files and folders to show when using the “opendir” function is that the directory which is opened, is the one created when the registration was done is used by going to the main folder of the webspace. Then adding the Username to the directory, since that is the one created.



Also when showing every file and folder name a delete hypertext field is created to be used to delete the file or folder.  This hyper link sends the name of the file or folder to a function which check if it is actually a file or a folder first using the "is_dir()" and then if its a file, it deletes it using the unlink feature. If its a folder it first has to go into every file and unlink it one-by-one before deleting the directory since PHP would give an error if it tried to delete a folder which had any kind of content.






As explained before another function in the Webspace is the ability to Upload Files. This is achieved by using the file input and HTML; the user will select a file from his computer and then click the upload file button. The PHP code will check if the file size is larger than 2MB the file is not loaded an error is given. Also an error is given if the size of all the items in the folder used by the user plus the size of the file to be uploaded exceeds 10MB. I chose the limit to 10MB so that I did not need to upload a lot of files before the limit is reached and testing could be done properly. When the file is uploaded the page is reloaded using the HEADER function so an alertbox shows the user that the folder is created and it is now shown since the page is reloaded the new folder is now shown as well.

  

To Find out how much space is used, a function was created that will add every files' size to a variable in the main directory of the user, and then before uploading the file adding it to the size of the file that is going to be uploaded now. This is done because It could be that the file that will be uploaded now will exceed the maximum limit.



Another feature is to add new folders in the webspace. A Textbox along with button to add folder exists to make this function properly. This feature is achieved when pressing the “Add folder” button and the PHP script will take the value of the textbox and using the “mkdir” function in PHP a folder is created. Again the program checks if the folder already exists and if it does the folder is not created. After the folder is created the program uses the header so that the user will go back to the current page, so that an alertbox shows the user that the folder is created and it is now shown since the page is reloaded the new folder is now shown as well.



If the User accesses a folder inside his webspace, every item uploaded or folder created will be now inside that particular folder. Also if the user wishes to access the main folder again, he does not need to log out and log back in. The "Back to Previous Directory" will take the user up one level in the directory using the "dirname" function in PHP which gives you the directory name of where an item currently is so by giving it the current path, the directory which it will give us is the folder we need to go back to the previous directory. A validation is created so that the previous will not go further than the main screen of the specific user.




Also a very simple logout button is used to unset and destroy the sessions used in when logging in and the page is redirected back to the login page. 




In the end this is what the main page looks like.




Conclusion

After finishing everything I made sure that the website is compatible in all browsers, since I kept the CSS to a minimum, everything was the same in every browser tried (Google chrome, Firefox 4, Internet Explorer).


Although I have spent a lot of time on this coursework I still believe that a lot of improvement on features could be done such as Downloading files that one has uploaded, creating a folder offline for the user which would sync with the webspace, or having an e-mail sent to the user whenever he registers first and a feature to send him an e-mail with the password whenever he forgets it.

Also I think that some improvements on styling could be done but since I never had any styling or designing experience I tried to keep things simple.

Some limitations I have done creating this Coursework was that every page had only 1 file that had all its PHP scripts. This proved to become quite messy when fixing errors or trying to find specific code. Next time I would make sure to structure the scripts into more files for at least every main function and link them to the main page using the "include" function.

As For my Experienced when using PHP over these last few weeks, coming from .NET Developer who never did any Web Development before was, that PHP although a very powerful scripting language still leaves us some things to be desired such as a good Debugging tool and maybe its strictness over Case-sensitivity can be a little tedious.