Network code bug

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

poelzi
Engineer
Engineer
Posts: 1
Joined: 09 Aug 2004 00:08

Network code bug

Post by poelzi »

Hi,

if found the network code bug that results in random disconnects i think.

The Problem is, that the code thinks, that the data stream is continuous, but it isn't. The network connection is made via udp, which has the feature to not resend lost packages.

So, there are two possible ways to fix:

Use TCP instead of UDP. But this is not a good solution. The most games use udp, because the resend of the package would be outdated anyway.

Instead the code need more error checks. First of all, all packages have to be signed by a prefix magic and a suffix magic plus checksum.

A package starts with a magic, this could be a char with suffix checksum check or a string like "oTtdS". Without suffix checksum, a single char isn't enough. But i suggest:

byte magic
byte packet_len
byte type
byte packet[packet_len]
byte magic
byte chksum[4]

checksum algorithm could be something like crc32, not to strong because we don't need cryptographic security :)

the parse method looks for the next magic, then checksums from packet_len to packet[packet_len]. Looks for the magic and compares the checksums, if the are vaild, continue.
If the checksums doesn't match, search for the next magic and discard everything before the new magic.

Using UDP does also require to resend updates, the server can't assume the client state.
User avatar
dominik81
OpenTTD Developer
OpenTTD Developer
Posts: 768
Joined: 16 Aug 2003 12:55
Location: Bonn, Germany

Re: Network code bug

Post by dominik81 »

poelzi wrote:if found the network code bug that results in random disconnects i think.

The Problem is, that the code thinks, that the data stream is continuous, but it isn't. The network connection is made via udp, which has the feature to not resend lost packages.
UDP is only used to find the server on a network. The game runs through TCP. And TCP is perfect for this, because no data is lost and a little lag does not hurt, because OpenTTD is not a close combat type of game. I haven't looked into the desynch problem yet, but if you have a fix, it's of course greatly appreciated. :D
"There's a readme that comes with the source. I suggest you read it."
- Korenn
}T{Reme [Q_G]
Route Supervisor
Route Supervisor
Posts: 389
Joined: 04 Feb 2004 23:24
Contact:

Post by }T{Reme [Q_G] »

Desynching seems to happen very often as it switches from one month to the other. I first thought the monthly autosave (almost required in net play) was causing the problem... so we both turned it off but I was still getting disconnected... so my next guess is the difference in computing power (dual P3 733MHz vs. P4 2.5GHz) is the likely cause... would there be some way for the client that is "ahead" of everyone to wait a few frames... just to resynch the game?
Siggy not gonna work unless someone allows javascripting...
User avatar
Killer 11
Tycoon
Tycoon
Posts: 2463
Joined: 06 Jan 2004 18:38
Location: Kaunas, Lithuania
Contact:

Post by Killer 11 »

I already suggested that developers could make the lan game like in starcraft were the slowest performing pc dictates the speed that others folow so there would not be any desynch.
And you can get an example of that multiplayer in c coding here: http://www.relic.com/rdn/index.php register and download the homeworld source it should contain multiplayer.c or something like that the code is in c and the game's multiplay runs in a way that i said before :wink:
User avatar
lucaspiller
Tycoon
Tycoon
Posts: 1228
Joined: 18 Apr 2004 20:27

Post by lucaspiller »

I also think desyncs might have something to do with differences in computing power. For example if you have the server on a fast PC (e.g. 2ghz processor) the game will run at a speed that is good for that computer, but if a client is an old PC (e.g. 200mhz processor) with full detail options on it may not be able to keep up with the speed at which the server is running.

The way in which (I think) the game is kept in sync is by syncing the random seed number and the server sending out to the clients what frame it is on. This only happens every few frames though rather than every frame. I don't really know how the frame system affects gameplay but if the client is a few frames behind the server I don't think it would hurt to skip a few, or if it is ahead to wait a bit.

I will do some more experimenting to see if I can find anything out because this is one of the most annoying and on-going bugs in the game that still hasn't been solved....
No longer active here, but you can still reach me via email: luca[at]stackednotion[dot]com
User avatar
Zahl
Engineer
Engineer
Posts: 27
Joined: 23 May 2004 13:19
Location: Germany
Contact:

Post by Zahl »

I can tell it is not a problem with fast and slow machines.
Just sync the settings and use axactly the same version and
everything is fine. Just played about 3 hours with a friend:
Duron 500MHz vs. Athlon XP 2500+ ;)
}T{Reme [Q_G]
Route Supervisor
Route Supervisor
Posts: 389
Joined: 04 Feb 2004 23:24
Contact:

Post by }T{Reme [Q_G] »

Hrm... did some thinking and I'm not sure if it's entirely cpu power related.... been running on fast mode occasionally with a friend of mine... even with 3 people... no desynch (large rail networks for each player)... yet it still randomly lets people desynch on normal speed.
Siggy not gonna work unless someone allows javascripting...
User avatar
teeone
Transport Coordinator
Transport Coordinator
Posts: 307
Joined: 05 Aug 2004 20:54
Location: Oregon, USA

Post by teeone »

I tried fast forward with 1 other person and it desync'd me the next month.....although we were having desyncs A LOT on normal speed too...but fast forward seemed to trigger it. Is fast forward even officially "supported" for multiplay?
User avatar
Korenn
Tycoon
Tycoon
Posts: 1735
Joined: 26 Mar 2004 01:27
Location: Netherlands
Contact:

Post by Korenn »

the speed of the different computers in a network game is totally insignificant. The server synchronises the game state before allowing things to continue so it will automatically go at the speed of the slowest computer/connection combination.

I played in an 8 player game on the internet for hours where most players were in brittain and using a modem dial-up. there was maybe 1 desync, but that player reconnected and all was fine again.
}T{Reme [Q_G]
Route Supervisor
Route Supervisor
Posts: 389
Joined: 04 Feb 2004 23:24
Contact:

Post by }T{Reme [Q_G] »

You sure about that Korenn? I played it even on a 100Mbit LAN connection (computers side by side) with both comps running past the 1.5GHz... yet still I got randomly desynched every 20-30 minutes or so.
Siggy not gonna work unless someone allows javascripting...
User avatar
Korenn
Tycoon
Tycoon
Posts: 1735
Joined: 26 Mar 2004 01:27
Location: Netherlands
Contact:

Post by Korenn »

very sure. although that was the official release, not the nightly build, and the nightly build is not garantueed bug free.
User avatar
dominik81
OpenTTD Developer
OpenTTD Developer
Posts: 768
Joined: 16 Aug 2003 12:55
Location: Bonn, Germany

Post by dominik81 »

Fast forward is not supported in multiplayer games.
"There's a readme that comes with the source. I suggest you read it."
- Korenn
}T{Reme [Q_G]
Route Supervisor
Route Supervisor
Posts: 389
Joined: 04 Feb 2004 23:24
Contact:

Post by }T{Reme [Q_G] »

Not supported true... but working for sure... but hell, the entire networking feature is not supported (reason why the 2 player button don't work)
Siggy not gonna work unless someone allows javascripting...
User avatar
teeone
Transport Coordinator
Transport Coordinator
Posts: 307
Joined: 05 Aug 2004 20:54
Location: Oregon, USA

Post by teeone »

}T{Reme [Q_G] wrote:Not supported true... but working for sure... but hell, the entire networking feature is not supported (reason why the 2 player button don't work)
Yeah took me alittle bit to figure out the command line way to get it running :)
qery
Engineer
Engineer
Posts: 8
Joined: 25 Oct 2004 15:14
Location: Bratislava Slovakia
Contact:

Post by qery »

i tryed openttd over internet but i was immedietly disconnected and i dont know why??
I have Duron 1800 and 2 MBit connect and my friend has got Athlon 2000+ and 1 MBit.
We have the latest version 0.4.0.
What about that?
User avatar
Darkvater
Tycoon
Tycoon
Posts: 3053
Joined: 24 Feb 2003 18:45
Location: Hong Kong

Post by Darkvater »

Wow, 0.4.0 :D Can you send it to us? Then we can just do an immediate update from 0.3.4 to 0.4.0 and not go through this process is lots of work to do :P
Anyways, 0.3.4. network is really buggy unfortunately. You can try the SVN version; but pretty soon a new network is out that will be a lot and lot better!
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
qery
Engineer
Engineer
Posts: 8
Joined: 25 Oct 2004 15:14
Location: Bratislava Slovakia
Contact:

Post by qery »

ooooops ;)
sorry i have mistaken :)
ill try svn but i dont know how to get it ... are that only source codes? or is there a compiled version?
User avatar
Darkvater
Tycoon
Tycoon
Posts: 3053
Joined: 24 Feb 2003 18:45
Location: Hong Kong

Post by Darkvater »

2 magic words: nightly build

(look in General OpenTTD)
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
qery
Engineer
Engineer
Posts: 8
Joined: 25 Oct 2004 15:14
Location: Bratislava Slovakia
Contact:

Post by qery »

hmm doesnt work :(
What about new version? ;)
User avatar
Celestar
Director
Director
Posts: 574
Joined: 02 Jul 2004 10:56
Contact:

Post by Celestar »

We are just preparing a completely new network code, and we have high hopes there will be a release with it this month.

Celestar
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest