Network Game

Blitz3D Forums/Blitz3D Programming/Network Game

asdfasdf(Posted 2004) [#1]
Can a Network game be played over the internet or does it have to be on a network.


Gabriel(Posted 2004) [#2]
The internet *IS* a network, so of course the answer is yes.


Jeroen(Posted 2004) [#3]
IMHO that's a bit short sighted. Theoreticly it may be the same, practicly there are differences:

* NAT, Firewalls
* slower connections (if the game is LAN only you might not need to optimize data transfer as much)
* Greater distances require good netcoding, e.g prediction.


semar(Posted 2004) [#4]
@Blitz Programmer,

I agree with the other posters here. Only one thing, yes Internet is a network, but the DirectPlay commands won't work.

If you want to play in internet, you have to use TCP or UDP. If you want to play in LAN, you can use also DirectPlay.

Bare in mind that the speed of these three protocols is different; for example, DirectPlay is very reliable, but really slow. TCP is also reliable, and faster than Directplay.

UDP is the fastest you can use, but not reliable, which means, a sent UDP packet could be lost in space, or arrive at destination not exactly in the same order it was sent, in respect with the other packets.

DirectPlay and TCP are great for turn-based games, UDP is the way to go for fast paced action games. I use UDP in BomberLAN, a remake of Amigas Bomberman, and in LAN it works really smooth.

Sergio.


Strider Centaur(Posted 2004) [#5]
If you want to create internet capable games, use BlitzPlay, its super simple and more than fast enough for just about anything. As far as Direct Play, it also works over TCP/IP, didn't used to, but I believe in DX6 they made the mover from only IPX/SPX to adding TCP/IP support also. However, Direct Play does not do well with NAT based firewalls and is really a joke by todays standards anyway. BlitzPlay Pro will do everything you want and will only take you a day or two to get familure with.

Of course you could hammer out your own netcode, but then you wouldn't really be making efficiant use of your time, spending hours writing code that is already available, when you could instead be writing code for your game. :)

OK, I can see reinventing the wheel for educational reasons or even self satisfaction, but don't do it because your a purist. LOL


Dirk Krause(Posted 2004) [#6]
Check Jeremy Allessi's great Code Example in the Code Archive. It's a full internet capable multiplayer game.


Regular K(Posted 2004) [#7]
Your not reinventing the wheel, your just adding 1 more degree to a full circle :P


asdfasdf(Posted 2004) [#8]
I want to play a game I made with a friend. I'm trying to see if TCP or UDP or DirectPlay would be better. Its a shooter game so it sends the pos of the enemy,join msg,mail,reset a player,Quit,Win/lose. the pos of the enemy is sent every frame.


Gabriel(Posted 2004) [#9]
I've found BlitzPlay very easy to implement, so you might want to check that out. There's a free version and a paid version, but I've only tried the paid version so I don't know how full-featured the free version is.

http://www.blitzcoder.com/blitzplay


asdfasdf(Posted 2004) [#10]
I'm having a problem with multiple enemys. It won't display any enemies when somebody joins.



asdfasdf(Posted 2005) [#11]
I've got it working so that you can create players and others stuff. My positioning system isn't working. The enemy will appear 0,0,0 but won't moveafter that.

This is where the pos code is
If NetMsgType() = 2 Then
		start = Instr(NetMsgData(),",")
		x = Left(NetMsgData(),start - 1)
		start2 = Instr(NetMsgData(),"|")
		y = Mid(NetMsgData(),start + 1,start2 - 1)
		z = Right(NetMsgData(),Len(NetMsgData()) - start2)
		For thisEnemy.EnemyType = Each EnemyType
			If thisEnemy\Id = NetMsgFrom() Then
				PositionEntity thisEnemy\mesh,x,y,z
			EndIf
		Next
	EndIf

P.S. This is my 100th post!!!


wizzlefish(Posted 2005) [#12]
I can't help - don't have a clue what network play is about... :(


Ross C(Posted 2005) [#13]
Whats the point in posting then ;)

dammit, oh the irony :D


Strider Centaur(Posted 2005) [#14]
Are you sure you are sending the Global position in and not the movement info relative to the enemies last position? This is a common misstake.

Since Moveentity is based on movement from the relative position and facing, the values used there are no use to positionentity. What you want to make sure you are sending is, EntityX, EntityY and EntityZ, as well as the yaw, pitch, roll of the same type, if you use those.

I see you are sending the EntityX(player) etc. However you may want to try sending EntityX(player,1) and then use positionentity with the global flag set for data recieved from the net.

Just a idea, you may want to coment some of that code so its a tad easier to see what your trying to achieve, would make debugging alot easier. :)


boomboom(Posted 2005) [#15]
Ok, I am a network noob also.

How does blitz know what todo with the incoming data. Say i stream the xyz co-ords

34 56 21, how does blitz know thats the xyz and put it the right type field to then act on it?


asdfasdf(Posted 2005) [#16]
@boomboom
I decode the xyz and then set it. Blitz doesn't know to do that.
Heres where I send the position:
If frame = 25 Then
		SendNetMsg 2,EntityX(player) + "," + EntityY(player) + "|" + EntityZ(player),id
		frame = 0
	EndIf



Strider Centaur(Posted 2005) [#17]
Well I would place a stop in the if test after the Type thisEnemy\ID test, to make sure you are getting to the PositionEntity, just creating the mesh will position it at 0,0,0, so if that test fails they will always stay at the creation point.

If thisEnemy\Id = NetMsgFrom() Then
stop
.
.
.
end if


Actually, if you are only supporting 1 other player, you dont really need to test for anything but NULL and just perfrorm the position every frame.

Again just some ideas.


boomboom(Posted 2005) [#18]
ok Blitz Programmer, so say the message is sent like:

21,23|43 (if i read your example correctly) and the other side (say server) get its

How do you then find out if that piece of information is the co-ords? Rather than something say, the animation of the character?

I could understand putting in 2 leading characters such as

PL,21,23,43 Then sending that as a string, then when receaving it looking fr the 2 leading characters and processing it like that.

Does this make sence?


asdfasdf(Posted 2005) [#19]
Yes. I set the NetMsgType to 2 which is the msgtype for position. There isn't a server really. The first player is the server but it doesn't sit there and watch, the server/player plays.
@Strider Centaur
I had it so that only one other player could join but now I want it to have mutiple players at once so that other people can play.


boomboom(Posted 2005) [#20]
I see, and if I was not using the direct play method (say I was using the tcp stream) is using leading characters the best way?

Really I need to know how to package my data for it to be sent, then unpack it to process it

would a good way be to send it looking something like this

"Bob,32,24,53,0,0,42"

Then untankle it?


asdfasdf(Posted 2005) [#21]
You could. I'm not that great at TCP though. I did write a program to send mail. I tried the make a new IP address on my network but that didn't work. I can do BlitzPlay sorta well.
Client
tcp=OpenTCPStream("192.168.2.85",2000)

;msg type,x,y,z
WriteLine tcp,"2/20|30\30"


Server
tcp=CreateTCPServer(2000)

Type = AcceptTCPStream(tcp)

;Uncode here



Douglas(Posted 2005) [#22]
Is DirectPlay that bad? I did some ping/bandwidth tests a while back with DirectPlay and BlitzPlay doing Tennessee to Georgia and they performed just about the same.


Strider Centaur(Posted 2005) [#23]
I think BlitzPlay(BP) is just easier to use over all. For one BP seems to handle NAT much better on the client side.

@Blitz Progeammer
Getting more than one to work is as easy as getting one to work, just make sure your players are defined in types and spawn a new instance of that type. Just use the player ID to track what message should update what player. Then loop through all the players in the type list with the good ole "For typename.type = each type ..... Next" loop and perform the updates.

One nice thing BP offers is a spline routing to help deal with lag delays. Also support for Gnet that makes finding a server much nicer. :)


mrtricks(Posted 2005) [#24]
Can you use UDP and TCP both in the same session? I.E. use UDP for info that needs to get there quick and TCP for info that can be a bit late but MUST arrive?


asdfasdf(Posted 2005) [#25]
You could open UDP and TCP and the client would have to connect to both. The client would have to check both. I don't know if it would work but it might.


Strider Centaur(Posted 2005) [#26]
Yes you can mix UDP and TCP, but would need to use 2 ports. One port for TCP and the other port for UDP. Then you would have to read each port seperatly. This does not mean you would need to create 2 totally seperate messaging scheams( codes ), you could simple call your NetHandler(Message) function after reading in a stream from either port. This is as long as you keep the message format consistant.


mrtricks(Posted 2005) [#27]
Okay... not sure when that might be appropriate but who knows?

I looked through the online B3D manual last night and the network commands are documented awfully! I couldn't make head nor tail of them - the manual could do with a separate tutorial on network coding. I looked elsewhere online for tutorials and found a few articles on demaster.org, but I still don't really understand what a port actually is and how it works.


Strider Centaur(Posted 2005) [#28]
Save yourself time and frustration and get BlitzPlay, Surreal has done a awesome job of making Net Coding easy. There is a Lite version which will probably do everything you will want in a game. But if you find it usefull, please help support Surreal by buying the PRO version. :)

Heres the URL
http://www.blitzcoder.com/blitzplay/


_PJ_(Posted 2005) [#29]

I looked through the online B3D manual last night and the network commands are documented awfully! I couldn't make head nor tail of them - the manual could do with a separate tutorial on network coding. I looked elsewhere online for tutorials and found a few articles on demaster.org, but I still don't really understand what a port actually is and how it works.



Yeah. Tell me.

The examples dont seem to make it much easier either.


fall_x(Posted 2005) [#30]
but I still don't really understand what a port actually is and how it works.

I don't think it's up to the blitz manual to point out the basics of networking. After all, the manual doens't explain how to do other basic things like clicking your mouse either.

Anyway, a port is just a number that is used by the computer to identify which program it has to send the data to.
For instance, if you have a webserver program running and you've got it configured to listen to port 80 (default for web), and browser makes a connection to your computer on port 80, your computer will send it to the webserver program.


Strider Centaur(Posted 2005) [#31]
Hmm, a port is just a way to identify a buffer in the network sub systems.

It is evem possible to have multiple apps looking at the same port at the same time, but this is highly unusuall. Examples of this are Sniffers that analyze all ports, transparantly.

For TCP/IP and UDP all you really need is the IP address and a port to connect to. The Server Listens to connections to a port and the client make connections to a remote port.

If you really want to get way to deep into TCP and the other things related like ICMP and what not, you may want to check out "UNIX Network Programming", an excelent book on the subject. Its usually a big white book with blue letters.

That book covers pretty much everything, along with example "C" source code to see how things are handled in code.

I know its UNIX, but once you understand that, then you can tackle any SOCK interface ever made real easy.


asdfasdf(Posted 2005) [#32]
I'm having problems with freezing when another person joins. It will freeze one computer (the joiner). I think it is because it isn't get the host player correctly.