Online programming

Blitz3D Forums/Blitz3D Programming/Online programming

slenkar(Posted 2005) [#1]
Hi is there a tutorial anywhere for the general theory of writing an online 3D blitz game?

I had a look at the startnetgame command in the manual but there is much more to the subject, I also looked at FPSNET which is great like the castle demo,
but like the castle demo it just gives you source code which I cant understand unless I get to know it a bit at a time from other examples.

I mainly used the castle demo to see how things should be done, instead of actually learning how to build a similar program for myself.


GNET confuses me also,
In the code archives are mainly non-game posts or advanced stuff


Jeremy Alessi(Posted 2005) [#2]
FPSNet I figured would answer most peoples questions but I know I didn't comment it too well so here goes a little general theory.

First you want a way for people to find other people to play with. That's where GNet comes in. It lists your computer's IP address along with some game information on a web server (with a hard coded address like www.blitzbasic.com in stock GNet) so that other people can find your game. So your game must be able to upload game information to GNet and also retrieve it to create a server list. The FPSNet example does this. GNet uses PHP and MySQL to store the information on a web server. Blitz connects to GNet through the HTTP port to send and get information ... just like a web browser.

After that it's pretty simple. You send messages between computers to update positions, chat, shots fired, score, etc, etc... You usually have reliable and normal messages. Reliable makes sure the message gets to the other computers but is slow.

What specifically did you want to know cause after typing that it seems simple and like I probably didn't answer your questions.


slenkar(Posted 2005) [#3]
Thanks for the reply, so using Gnet means you dont have to know SQL or PHP?
and when people use GNET they are using Marks website server to store a list of game servers?

The other confusing part is the actual structure of the program, (which could be learned from FPSNET I suppose but that would take longer than asking)

from what I saw, each player gets the same program which acts as a client or a server,and can even change from client to server when the server goes offline,

the confusing part for me is how does the program know when a player has been hit by a bullet?

Does the collision take place in the server,on the client, or is there an inbetween place,
the positions of the players and bullets are sent to each player using text files right? but how many per second,


also what happens when the player moves his character?
does a message get sent to the server or does the client move him?

what does the decodeincomingmessage) function actually DO, the title of the function is very descriptive but the code in the function is difficult to understand,and why do the messages have to be encoded in the first place?

thanks for the answers


Jeremy Alessi(Posted 2005) [#4]
That DecodeIncomingMessage() function is more complex than it possibly needs to be but the basic idea is to divide up a long string into shorter strings that have meaning like an entity's x position.

Each part of the string is separated by a "," and the end of the whole string is a "-". What happens is that the message gets divided up and each part is placed in the incoming$() array. Then the client reads the incoming$() array for the information all depending on the type of the incoming message.

So for example we'll look at the shotgun (this is from the FPSNetUpdate in the Networking section of the archives).

SendNetMsg(2, "2," + Left(Str(shot), 1) + "," + Left(Str(shot2), 1) + "," + Left(Str(shot3), 1) + "-", p\iD, op\iD, 0)


This is the message that sends if the shots hit (the game doesn't use actual projectiles which would be more complex than linepicks which FPSNet uses).

This reads the message:

Case 2
			
				p.Player = Object.Player(localPlayerPointer)
				CreateSomeParticles(EntityX(p\mesh[1]), EntityY(p\mesh[1]), EntityZ(p\mesh[1]), 255, 0, 0, 10)
				
				If justDied# + 500 < MilliSecs()
					DecodeIncomingMessage(NetMsgData$())
					Select incoming$(1)
						Case 1
							health# = health# - 5
						Case 2
							count = 0
							If incoming$(2) <> 0
								count = count + 1
							EndIf
							If incoming$(3) <> 0
								count = count + 1
							EndIf
							If incoming$(4) <> 0
								count = count + 1
							EndIf
							health# = health# - (5 * count)
						Case 3
							health# = health# - 25
					End Select
				EndIf
				
				If health# <= 0
					health# = 100
					PositionEntity(p\mesh[1],5,1,Rand(0, 50))
					SendNetMsg(3, "1", p\iD, NetMsgFrom(), 1)
					CreateSomeParticles(EntityX(p\mesh[1]), EntityY(p\mesh[1]), EntityZ(p\mesh[1]), 255, 0, 0, 100)
					SendNetMsg(5, "1",p\iD, 0, 0)
					justDied# = MilliSecs()
				EndIf


Case 2 means if this is message type 2 indicated by our sent message as:

SendNetMsg(2,


So if we have a message of type 2 then make some particles where we're getting shot and if we haven't just died lets take some damage.

If incoming$(1), incoming$(2), or incoming$(3) isn't a zero then we got hit by 1 or possibly all 3 shots from the shotgun so let's take some damage.

Also, yes GNet uses Mark's server to list games and you don't need to know PHP/MySQL to use it ... unless you want to move it to your own server which I did for some things.

As for movement, the client moves his/her own player and then tells everyone else where he/she is.

It's been a while since I wrote this code but that's the general idea. This code is a simple peer to peer example game. If you want to start getting complex then a strong client server architecture is required. The Torque Game Engine handles more complex things (like projectiles with ballistics) easily and I probably wouldn't recommend trying to write your own engine dealing with the complex stuff right off the bat. Make some peer to peer games to understand why or what the other stuff is needed for.


slenkar(Posted 2005) [#5]
hmm OK looks like it will take a long time to work out all the details,
Ill give it another shot

thanks for the help