Amiga.org

Coffee House => Coffee House Boards => CH / Science and Technology => Topic started by: motorollin on February 23, 2008, 11:15:16 AM

Title: Looking for advice on which web language to use
Post by: motorollin on February 23, 2008, 11:15:16 AM
I'm once again thinking about writing a web-based space trading/combat game (I don't like to say a web-based version of Eve as that's a big job, but that's what it would be modelled on). I did make some progress with this the last time I started, with a database structure to contain regions of space containing solar systems, which in turn contained planets. There was a hyperspace system to jump from one region to the next, and you could fly from one planet to the next, land on planets, buy and sell goods , refuel, send/received messages to/from other players. It was quite good!

The game was written in PHP, with the frontend being basic HTML - nothing fancy as I want the game to be accessible from as many devices and browsers as possible. Unfortunately, PHP was also the downfall of the game. Because it only updated when the page refreshed, I could find no way to notify the user of new messages unless they did something which refreshed the page. Also I couldn't think of any way of implementing combat in real time if the page doesn't update automatically. It would also be difficult to implement things like being intercepted during travel.

So I'm hoping there is a language out there which can do what I want. I need the backend to be able to force the web page to refresh in case something happens in the background (user gets contacted/attacked/whatever, or a move is made during combat). But the frontend should still be basically plain HTML to make sure it works in any browser.

Is there any way to accomplish what I want?

--
moto
Title: Re: Looking for advice on which web language to use
Post by: Speelgoedmannetje on February 23, 2008, 11:45:16 AM
Java. (as applet)
Title: Re: Looking for advice on which web language to use
Post by: bloodline on February 23, 2008, 12:42:12 PM
Quote

Speelgoedmannetje wrote:
Java. (as applet)


I don't think Java would be good for this... I would read up on HTML5. ECMAScript is your friend :-)
Title: Re: Looking for advice on which web language to use
Post by: Speelgoedmannetje on February 23, 2008, 12:55:39 PM
:lol:
Title: Re: Looking for advice on which web language to use
Post by: motorollin on February 23, 2008, 01:00:56 PM
I'm not sure I want to use Java as it will limit the devices which will be able to use it. How easy is Java to learn? I've got some experience writing games in C++ so if the syntax is similar I will consider it.

--
moto
Title: Re: Looking for advice on which web language to use
Post by: Speelgoedmannetje on February 23, 2008, 01:04:53 PM
It's quite similar.
But you don't have to use pointers as much.
Title: Re: Looking for advice on which web language to use
Post by: bloodline on February 23, 2008, 01:15:26 PM
Quote

motorollin wrote:
I'm not sure I want to use Java as it will limit the devices which will be able to use it. How easy is Java to learn? I've got some experience writing games in C++ so if the syntax is similar I will consider it.

--
moto


Both Java and ECMAScript (or whatever you want to called it) are modeled on C++ (though a three use slightly different OOP paradigms)... So knowing any of them will allow easy working with the others.

As Speel knows, I'm rather keen on ECMAScript since every modern browser can run it... You can prototype quickly and it's very fault tollerant... The only thing I don't like is the Document Object Model, but once you learned it it's fine!
Title: Re: Looking for advice on which web language to use
Post by: Speelgoedmannetje on February 23, 2008, 01:24:58 PM
You cannot use classes in ECMAScript like you can use them in Java. And it certainly does not have as much libraries as Java. And it's just plain messy.
Title: Re: Looking for advice on which web language to use
Post by: motorollin on February 23, 2008, 01:46:12 PM
If I use ECMAScript/JavaScript, how can the backend tell the frontend that something is happening of which the user needs to be made aware? I thought JavaScript could interact only with elements on the page, not with anything external like a database.

--
moto
Title: Re: Looking for advice on which web language to use
Post by: Speelgoedmannetje on February 23, 2008, 01:53:35 PM
Maybe in combination with CGI.
But really, JavaScript is a nightmare which I want to forget ASAP.
Title: Re: Looking for advice on which web language to use
Post by: motorollin on February 23, 2008, 02:21:34 PM
Javascript and CGI will leave me in pretty much the same situation as PHP. Yes CGI/PHP can obtain information from the database about where the player is and their status, but this will only occur when the page loads and the script runs. There is no way I know of for the server to say "user with this session ID: something has just changed, force the page to refresh". The only workaround I can think of is to have a frame continually refreshing and running a script to check for these things and then refresh the main window if anything changes. But this is messy and inefficient, is likely to lead to the focus being stolen while the user is doing something, will cause massive strain on the database, and will not be ideal during real-time combat.

I'm starting to think Java is the only alternative, but I was really hoping to keep this as simple as possible so that it will run on pretty much any browser.

--
moto
Title: Re: Looking for advice on which web language to use
Post by: bloodline on February 23, 2008, 02:33:05 PM
Yeah, I would use a hidden iframe with a 10 sec refresh to sync the database... It you take the java route, to be honest you would be better off using C and SDL... Then compile a native version of the client for each target platform... Yes, I really don't like java :-)
Title: Re: Looking for advice on which web language to use
Post by: motorollin on February 23, 2008, 02:41:48 PM
I would prefer not to have to learn a new language. But at least a Java applet can run in a browser, meaning players can connect from any machine with a Java capable browser. I'm just trying to make the software as flexible as possible, so it's accessible from pretty much anywhere.

The advantage of sticking with PHP is that it is really, really easy to interface to the back-end using PHP's MySQL interface. I have no idea how "real" online games work - presumably they don't just read values from a database to get status and update/insert rows to update the database with any changes? I would guess they have some kind of direct connection to proprietary software on the server, but I would have no idea how to start with coding something like that.

--
moto
Title: Re: Looking for advice on which web language to use
Post by: Speelgoedmannetje on February 23, 2008, 02:58:00 PM
Quote

motorollin wrote:
but I would have no idea how to start with coding something like that.
I guess you know how to program object oriented? And you have learned about software design patterns? When you can you know it won't be much of a problem :-)
Title: Re: Looking for advice on which web language to use
Post by: motorollin on February 23, 2008, 03:06:26 PM
Quote
Speelgoedmannetje wrote:
I guess you know how to program object oriented?

Yes. When I wrote my GP2X GridWars clone that was all object oriented (C++).

Quote
Speelgoedmannetje wrote:
And you have learned about software design patterns?

I know what they are, but I have never used one. I don't like the idea of trying to make my game fit in to a template.

Quote
Speelgoedmannetje wrote:
When you can you know it won't be much of a problem :-)

Depends on whether I can understand the pattern :lol:

--
moto
Title: Re: Looking for advice on which web language to use
Post by: Speelgoedmannetje on February 23, 2008, 03:50:16 PM
Quote

motorollin wrote:
Quote
Speelgoedmannetje wrote:
And you have learned about software design patterns?

I know what they are, but I have never used one. I don't like the idea of trying to make my game fit in to a template.
It's not template based, it's making use of ways to program. Ways which already have been thought out by experienced programmers.
Like the pattern Model-View-Controller (http://java.sun.com/blueprints/patterns/MVC-detailed.html)
Title: Re: Looking for advice on which web language to use
Post by: motorollin on February 23, 2008, 04:31:13 PM
OIC. I would be interested to see how an online game communicates with the back-end and keeps synchronised. Any ideas when I can get information on design patterns for things like this?

--
moto
Title: Re: Looking for advice on which web language to use
Post by: motorollin on February 23, 2008, 04:35:53 PM
Hmm, I wonder if this would be any better than JavaScript:

http://en.wikipedia.org/wiki/AJAX

"A primary characteristic is the increased responsiveness and interactivity of web pages achieved by exchanging small amounts of data with the server "behind the scenes" so that entire web pages do not have to be reloaded each time there is a need to fetch data from the server."

--
moto
Title: Re: Looking for advice on which web language to use
Post by: Speelgoedmannetje on February 23, 2008, 05:12:19 PM
Quote

motorollin wrote:
OIC. I would be interested to see how an online game communicates with the back-end and keeps synchronised. Any ideas when I can get information on design patterns for things like this?

--
moto
I'd use (and have used) a threaded method in combination with observer/observable implementation.
Title: Re: Looking for advice on which web language to use
Post by: Speelgoedmannetje on February 23, 2008, 05:12:59 PM
Quote

motorollin wrote:
Hmm, I wonder if this would be any better than JavaScript:

http://en.wikipedia.org/wiki/AJAX

"A primary characteristic is the increased responsiveness and interactivity of web pages achieved by exchanging small amounts of data with the server "behind the scenes" so that entire web pages do not have to be reloaded each time there is a need to fetch data from the server."

--
moto
But then I think Java is more common than Ajax.
Not sure though...Hm, well, it seems to be so.
Title: Re: Looking for advice on which web language to use
Post by: motorollin on February 23, 2008, 05:27:15 PM
Quote
Speelgoedmannetje wrote:
I'd use (and have used) a threaded method in combination with observer/observable implementation.

It's really the establishment of a connection between the client and the server and exchanging information between them which I am unsure about.

--
moto
Title: Re: Looking for advice on which web language to use
Post by: bloodline on February 23, 2008, 05:45:24 PM
Quote

motorollin wrote:
Hmm, I wonder if this would be any better than JavaScript:

http://en.wikipedia.org/wiki/AJAX

"A primary characteristic is the increased responsiveness and interactivity of web pages achieved by exchanging small amounts of data with the server "behind the scenes" so that entire web pages do not have to be reloaded each time there is a need to fetch data from the server."

--
moto


Yes AJAX would be perfect for this application... and the Logic language behind AJAX is JavaScript... That's where the J in AJAX comes from... Trust me, despite my ineptitude with German girls, I'm rarely wrong :-)


Anyway, don't you have some music homework to be doing? ;-)
Title: Re: Looking for advice on which web language to use
Post by: motorollin on February 23, 2008, 05:48:10 PM
Quote
bloodline wrote:
Anyway, don't you have some music homework to be doing? ;-)

Yes sir.... ;-)
Though if I'm honest, I'm a bit demotivated in that area at the moment :-(

--
moto
Title: Re: Looking for advice on which web language to use
Post by: bloodline on February 23, 2008, 06:09:08 PM
Quote

motorollin wrote:
Quote
bloodline wrote:
Anyway, don't you have some music homework to be doing? ;-)

Yes sir.... ;-)


Hahahahahha

Quote

Though if I'm honest, I'm a bit demotivated in that area at the moment :-(


I quite understand, I remember a great phrase... Professional means doing what you usually enjoy even when you don't want to...

Though by that token... I'm pretty musch a professional at every thing I do :-D
Title: Re: Looking for advice on which web language to use
Post by: motorollin on February 23, 2008, 06:33:35 PM
That's a good quote - so true! The problem is that your advice and suggestions have given me a lot to live up to! And unfortunately when I know something is going to be difficult or beyond my (current) abilities, I tend to lose motivation and give up prematurely. I've always been an underachiever... :roll:

--
moto
Title: Re: Looking for advice on which web language to use
Post by: bloodline on February 23, 2008, 08:31:12 PM
Quote

motorollin wrote:
That's a good quote - so true! The problem is that your advice and suggestions have given me a lot to live up to! And unfortunately when I know something is going to be difficult or beyond my (current) abilities, I tend to lose motivation and give up prematurely. I've always been an underachiever... :roll:


I can assure you, there is nothing that I have suggested which is beyond your abilities... you just need to devote some time to it. Set aside an hour tomorrow with your keyboard and sequencer and have a bit of a play... even if your first efforts sound a bit forced, that's good because you know you are doing it right, then you just need to develop that! :-)
Title: Re: Looking for advice on which web language to use
Post by: Speelgoedmannetje on February 23, 2008, 10:40:23 PM
Actually, Bloodline, what are you so much against Java?
Title: Re: Looking for advice on which web language to use
Post by: bloodline on February 23, 2008, 11:53:23 PM
Quote

Speelgoedmannetje wrote:
Actually, Bloodline, what are you so much against Java?


Very good question! The answer is manifold... And as such would take ages to explain... but I can summarise... I think it's inefficient, the problems that the original specification tried to solve don't exist any more and as such the focus is wrong. It tried to be between a VM and an Operating system... which makes it not very good at either... The Java VMs use a lot of CPU time... The JITs generate very slow code... When running Java on mobile devices, the battery life is severely reduced. Java is an ecosystem in it's own right... it keeps itself from the host system. Java Byte Code is not well suited to modern computer system, I think in the the last decade or so a better ByteCode could be developed... Hell 68K code running on Bernie's UAE JIT is more efficient!

For the purpose of Internet, JavaScript is much better... Though the DOM is a bit of a mess... fortunately, HTML 5 should fix all the problems :-)
Title: Re: Looking for advice on which web language to use
Post by: motorollin on February 24, 2008, 08:17:03 AM
Quote
bloodline wrote:
I can assure you, there is nothing that I have suggested which is beyond your abilities...

Hmm, ok if you say so :-)

Quote
bloodline wrote:
you just need to devote some time to it. Set aside an hour tomorrow with your keyboard and sequencer and have a bit of a play... even if your first efforts sound a bit forced, that's good because you know you are doing it right, then you just need to develop that! :-)

I actually have something in mind for a synth bass part, including the instrument. But you said it's best not to focus on sounds yet. Am I allowed to make an exception in this case? :-) And if I do my music homework, can I play with AJAX please? ;-)

--
moto
Title: Re: Looking for advice on which web language to use
Post by: uncharted on February 24, 2008, 09:34:02 AM
Quote

bloodline wrote:
Quote

Speelgoedmannetje wrote:

For the purpose of Internet, JavaScript is much better... Though the DOM is a bit of a mess... fortunately, HTML 5 should fix all the problems :-)


I've seen first hand that the above simply isn't true in many cases.  HTML 5's jam tomorrow is not really a convincing argument, especially when the track record of the major player's adoption of internet standards is so dire.
Title: Re: Looking for advice on which web language to use
Post by: Speelgoedmannetje on February 24, 2008, 09:35:53 AM
Quote

uncharted wrote:
Quote

bloodline wrote:
Quote

Speelgoedmannetje wrote:

For the purpose of Internet, JavaScript is much better... Though the DOM is a bit of a mess... fortunately, HTML 5 should fix all the problems :-)


I've seen first hand that the above simply isn't true in many cases.  HTML 5's jam tomorrow is not really a convincing argument, especially when the track record of the major player's adoption of internet standards is so dire.
You better get the quote right, I sure as hell didn't write that :nervous:
Title: Re: Looking for advice on which web language to use
Post by: Speelgoedmannetje on February 24, 2008, 09:44:02 AM
Quote

bloodline wrote:
Quote

Speelgoedmannetje wrote:
Actually, Bloodline, what are you so much against Java?


Very good question! The answer is manifold... And as such would take ages to explain... but I can summarise... I think it's inefficient, the problems that the original specification tried to solve don't exist any more and as such the focus is wrong. It tried to be between a VM and an Operating system... which makes it not very good at either... The Java VMs use a lot of CPU time... The JITs generate very slow code... When running Java on mobile devices, the battery life is severely reduced. Java is an ecosystem in it's own right... it keeps itself from the host system. Java Byte Code is not well suited to modern computer system, I think in the the last decade or so a better ByteCod could be developed... Hell 68K code running on Bernie's UAE JIT is more efficient!

For the purpose of Internet, JavaScript is much better... Though the DOM is a bit of a mess... fortunately, HTML 5 should fix all the problems :-)


OK. Java is very slow, but if you want to make more difficult program, JavaScript is plain unusable, and at best utterly messy.
And btw. considering complex programs written in Java, I very much doubt JavaScript will be any faster. Since JavaScript is a SCRIPT and thus for standard tasks it will be fast, but not for more complex tasks.
Title: Re: Looking for advice on which web language to use
Post by: bloodline on February 24, 2008, 10:52:58 AM
Yes Speel, I agree that javascript is not suitable large and complex tasks... But unfortunately, I don't think java is either, which is why I suggested Moto takes the C/SDL route... In js he can prototype quickly and work in any browser (including the iPhone and amiga)... With Java development is slower, more difficult and will need much more cross platform testing, the client will be a much heavier payload etc... By this time he would have been better off using C/SDL!
Title: Re: Looking for advice on which web language to use
Post by: bloodline on February 24, 2008, 11:05:14 AM
Quote

motorollin wrote:
Quote
bloodline wrote:
I can assure you, there is nothing that I have suggested which is beyond your abilities...

Hmm, ok if you say so :-)

Quote
bloodline wrote:
you just need to devote some time to it. Set aside an hour tomorrow with your keyboard and sequencer and have a bit of a play... even if your first efforts sound a bit forced, that's good because you know you are doing it right, then you just need to develop that! :-)

I actually have something in mind for a synth bass part, including the instrument. But you said it's best not to focus on sounds yet. Am I allowed to make an exception in this case? :-) And if I do my music homework, can I play with AJAX please? ;-)

--
moto


There are no hard and fast rules, anything that keeps you motivated is obviously a good thing. Programming synths is something I enjoy more than writing music, so sometimes I do just want to mess arround building a smally library of sounds to use at a later time :-)
Title: Re: Looking for advice on which web language to use
Post by: motorollin on February 24, 2008, 11:05:52 AM
BTW, is this an acceptable login/session management solution in PHP?

1. Username and password submitted to login script
2. Username and password checked against details in users table
3. Username and password match a user account
4. UserID retrieved from account
5. session_start();
6. Username and UserID stored in variables in $_SESSION[];
7. At the top of each page, session_start() is called

Is that secure enough?

--
moto
Title: Re: Looking for advice on which web language to use
Post by: motorollin on February 24, 2008, 11:07:10 AM
Quote
bloodline wrote:
There are no hard and fast rules, anything that keeps you motivated is obviously a good thing.

Oh go on, give me some hard and fast rules :lol: Ok, I'll try to dedicate some time to this again, probably tomorrow now since a visit to the in-laws is dragging on.... zzzzzzzzz......

--
moto
Title: Re: Looking for advice on which web language to use
Post by: Speelgoedmannetje on February 24, 2008, 11:17:08 AM
Quote

motorollin wrote:
BTW, is this an acceptable login/session management solution in PHP?

1. Username and password submitted to login script
2. Username and password checked against details in users table
3. Username and password match a user account
4. UserID retrieved from account
5. session_start();
6. Username and UserID stored in variables in $_SESSION[];
7. At the top of each page, session_start() is called

Is that secure enough?

--
moto
Make sure you store a password hash in the database, not the password itself.
(The password hash is derived from the password you submitted, this is done with a certain algorithm)
Also, make sure no SQL injection is possible.
Therefore, you must make sure you know all the things that are done with the database, and make a protocol according to that.
Title: Re: Looking for advice on which web language to use
Post by: Speelgoedmannetje on February 24, 2008, 11:20:05 AM
Quote

bloodline wrote:
But unfortunately, I don't think java is either,
It isn't. Java is widely being used for the most complex processes in business. It's all java, and it works.
Title: Re: Looking for advice on which web language to use
Post by: motorollin on February 24, 2008, 11:48:39 AM
Quote
Speelgoedmannetje wrote:
Make sure you store a password hash in the database, not the password itself.

Yes, the password is stored as md5. The login script then does $password=md5($password) before checking against the Users table.

Quote
Speelgoedmannetje wrote:
Also, make sure no SQL injection is possible.

Hmm, just done some reading about this. Sounds scary! Can I guard against this by processing all user input with addslashes()?

--
moto
Title: Re: Looking for advice on which web language to use
Post by: bloodline on February 24, 2008, 11:56:59 AM
Quote

Speelgoedmannetje wrote:
Quote

bloodline wrote:
But unfortunately, I don't think java is either,
It isn't. Java is widely being used for the most complex processes in business. It's all java, and it works.



I'm well aware of the scale of Java deployment... At uni they teach you nothing else... Just because something is widely deployed doesn't make it good does it?
Title: Re: Looking for advice on which web language to use
Post by: Speelgoedmannetje on February 24, 2008, 12:09:52 PM
Quote

bloodline wrote:
Just because something is widely deployed doesn't make it good does it?
It matters in which environment it's widely adopted. Big automization companies have well thought out what to use and what not to use.
Title: Re: Looking for advice on which web language to use
Post by: Speelgoedmannetje on February 24, 2008, 12:16:57 PM
Quote

motorollin wrote:
Quote
Speelgoedmannetje wrote:
Also, make sure no SQL injection is possible.

Hmm, just done some reading about this. Sounds scary! Can I guard against this by processing all user input with addslashes()?

--
moto
Well, as I stated earlier, if handle all the database stuff server side behind a protocol, and make sure the user input is restricted, there's not much that can go wrong.

Remember, the aim of programming is to reduce the capabilities of the computer.
Title: Re: Looking for advice on which web language to use
Post by: HenryCase on February 24, 2008, 02:24:31 PM
@motorollin
Not wishing to dissuade you from completing your project, as it would be a cool technical achievement, but I take it you know about Planetarion?

http://www.planetarion.com/
http://en.wikipedia.org/wiki/Planetarion
Title: Re: Looking for advice on which web language to use
Post by: motorollin on February 24, 2008, 04:48:15 PM
@Speel
Do you mean like a stored procedure?

@HenryCase
Yes I have seen that game. I don't like the emphasis on building a fleet. I like the concept in Eve where you are a pilot of a single ship and you can either go it alone, or collaborate with other players.

--
moto
Title: Re: Looking for advice on which web language to use
Post by: HenryCase on February 24, 2008, 05:04:49 PM
@motorollin
Fair enough. I wish for your success with this project.
Title: Re: Looking for advice on which web language to use
Post by: Speelgoedmannetje on February 24, 2008, 06:35:05 PM
Quote

motorollin wrote:
@Speel
Do you mean like a stored procedure?

--
moto
:-?
I meant that only the server must generate SQL commands, and that text input from the client side should have a check for invalid characters. Furthermore, sending data to the server should be quite direct, and *preferably* encrypted.
For instance, download the tool "WireShark", so you can (partially) test the vulnerability of your program.
Title: Re: Looking for advice on which web language to use
Post by: motorollin on February 25, 2008, 07:59:29 AM
Ok, will have to do some reading about this as I don't know how to do this. Thanks for your help guys!

--
moto