Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Client/Server Multiplayer

Author
Message
Bulleyes
22
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 16th Apr 2004 12:33
I had decided to use client/server for my game. Thus, the server will be the sole authority of maintaining the game state, while the client simply send the input to the server and render the state update from the server.

I don't want to have a dedicated server running. The person who is hosting the game will be a player in the game as well. The typical way what others do is, creating a server, while have the host player connect to itself (sorta like loopback). In this case, the implementation logic for the server and client side is cleaner.

I don't know really how to do this in DarkBasic. Can I call CREATE NET GAME, and then JOIN NET GAME in the same program? I believe not. Any advice and opinions will be much appreciated.

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Mussi
22
Years of Service
User Offline
Joined: 27th Jan 2003
Location: Netherlands
Posted: 16th Apr 2004 16:50
If you create a net game you've already joined the game.



Specs: AMD Athlon 1800, 256 DDRRam 266mhz, 80GB HD 7200rmp U133, Geforce 4 Ti4400 128mb
zircher
22
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 16th Apr 2004 18:38
DB is not multi-threaded. So, divorcing the server and client within the same program is not possible. I have not tried running a separate host program and client on the same machine, but that does seem possible.
--
TAZ

Bulleyes
22
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 16th Apr 2004 19:59 Edited at: 16th Apr 2004 20:06
Hmmm... Running the client and server on the same machine but DIFFERENT program is possible, I had already tried it. But what I wanted to do is putting the client and the server in the same running program instance. For example, when you host a game in Half-Life or Quake, it first create a server, and then create a client that represent the host player, and connect to the server that it created. But as you pointed out, DBpro is not multithreaded, I guess this is not possible.

Making the server a seperate program will be something like a creating a dedicated server. I am thinking of this possibility as well. But since the server need to do all the game state updating and stuff, thus it must be able to use those DBpro functions (like positioning object and collision detection, etc.) as well. I had seen most dedicated server doesn't have any user interface (or merely very simple GUI console). This is done such that the server doesn't need to have a good 3D accelerator as well, but just a powerful CPU.

I was considering of creating a dedicated server in DBpro, since I need the DBpro function (as I mentioned above.) But to avoid graphical update, I thought that I might omit the SYNC call in my game loop. I am wondering will this cause any problem? If what SYNC really do is merely rendering job then it should be fine. But what I afraid is SYNC will do other stuffs like updating the internal state of the 3D engine, e.g. object position, collision data, etc. If this is true, meaning that making a dedicated server might not be a feasible choice.

To further elaborate why seperating client and server logic apart is viable, this is to make the implementation logic cleaner and easier. The server will just responsible for receiving input from client and update the game state, no rendering or checking for user input from physical input device is needed on the server. At the client side, it just need to check for input from the user and send it to the server, maintain a subset of the game state, and update this subset as it receive the state update from the server, and render them on the display device. Combining the client and server logic in a single implementation under client/server model is somewhat messy, and more prone to bugs.

Phew... long paragraph. I hoped I didn't make anybody fall asleep.

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Mussi
22
Years of Service
User Offline
Joined: 27th Jan 2003
Location: Netherlands
Posted: 16th Apr 2004 20:22
Quote: "I hoped I didn't make anybody fall asleep."

To late ...
why make it client-server? just do a peer to peer



Specs: AMD Athlon 1800, 256 DDRRam 266mhz, 80GB HD 7200rmp U133, Geforce 4 Ti4400 128mb
UberTuba
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Brittania
Posted: 16th Apr 2004 21:23
Bulleyes Probably the best way to do this would be to make the server in c++, using db's net connection engine. then you just have to duplicate the net connection commands with commands to pass data between the c++ and the client

I'm Right and Reality is lying
TheOneRing
21
Years of Service
User Offline
Joined: 28th Aug 2003
Location: Right here.
Posted: 16th Apr 2004 23:07 Edited at: 16th Apr 2004 23:07
If I understand the question correctly, you want to know if you can have one computer be both server and a client at the same time without running a seperate server process (app, kind of like Rouge Spear). If so, check out this code (messy, sorry. Threw it together in a few minutes).

This is the server code. It establishes a server and connects to it itself.



Make sure to choose your connection...

Here is the client only code. You probably know how to do this...



Let me know if I'm close, or totally off-base.
Bulleyes
22
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 16th Apr 2004 23:56
@Mussi:

Thanks for your input. Peer to peer has many limitations and drawback. The most apparent challenges of P2P model is game synchronization to maintain state consistency among players. A very simple scenario, how do you make sure that when a missile hit a target will appear the same for all players taken into account of network latency and packet lost. (Yes, I know packet lost can be overcome by a guaranteed flag while sending, but it will incur some extra overhead if you understand how it works.) One word, latency is the biggest enemy of a real-time multiplayer game. Lockstep approach (an approach that ensure no players are allowed to proceed to the next frame until everybody is ready to proceed) is a simple way to overcome state consistency due to network latency. But this is not good, since it forces the player with fastest PC to match the speed of the slowest player.


@Uber:

Are you suggesting me to use IanM's interface library to code my server? Hmmm... sounds interesting, I haven't look into that possibility yet. Thanks!


@TheOneRing:

Quote: "If I understand the question correctly, you want to know if you can have one computer be both server and a client at the same time without running a seperate server process"


Ideally, I want both client and server running at the SAME PROCESS instance if the player hosts and play the game, just like when you host a network game in Warcraft, Quake, Half-Life, etc., you are the host and playing at the same time.

But what zircher pointed out was quite valid, this is not possible since DBpro doesn't support multithread, thus developing a dedicated server came across my mind. But my big question is, can I use the DBpro command normally if I never call to the SYNC command. The reason is I don't need to render the objects on the dedicated server, but I DO need to use the DBpro commands for positioning and rotating object, collision detection, etc. If the DBpro doesn't behave normally without calling the SYNC command, then I might need to scrap off this idea.

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Mussi
22
Years of Service
User Offline
Joined: 27th Jan 2003
Location: Netherlands
Posted: 17th Apr 2004 00:42
so how does this lockstep method work then?



Specs: AMD Athlon 1800, 256 DDRRam 266mhz, 80GB HD 7200rmp U133, Geforce 4 Ti4400 128mb
zircher
22
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 17th Apr 2004 00:56 Edited at: 17th Apr 2004 00:59
Quote: "The reason is I don't need to render the objects on the dedicated server, but I DO need to use the DBpro commands for positioning and rotating object, collision detection, etc."


Do you need the DBP commands? Imagine running a pure matehmatical model on the server core, perhaps using the Tokamak physics library?
--
TAZ

Also, using the hidden option in the IDE might help to reduce the server's load on resources.

Bulleyes
22
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 18th Apr 2004 07:37
@zircher:

I just need DBpro commands. I don't need those advance feature in Tokamak Library.

@Mussi:

Lockstep approach is very simple, and can be implemented easily on a single player game that is changing to multiplayer game. The game loop basically look like this

DO
Get input from local players and update the game state.
Get input from remote players and update the game state.
Render game state.
Send a "tick" message to all remote players.
Wait for the "tick" message from all remote players.
LOOP

The bottleneck is at the last statement, it is also the most crucial statement that ensure all players are in-sync with each other. This method will work nicely if your game doesn't required high interactivity such as FPS.

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Mussi
22
Years of Service
User Offline
Joined: 27th Jan 2003
Location: Netherlands
Posted: 18th Apr 2004 15:15
and what if one player starts to lag? then all go down with him?



Specs: AMD Athlon 1800, 256 DDRRam 266mhz, 80GB HD 7200rmp U133, Geforce 4 Ti4400 128mb
Bulleyes
22
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 18th Apr 2004 15:44
Yup, if you played Starcraft on the Internet, you will notice that.

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Mussi
22
Years of Service
User Offline
Joined: 27th Jan 2003
Location: Netherlands
Posted: 18th Apr 2004 15:48
then why not choose for guaranteed packets instead? you could do something like that only things like 'player hit a another player' are send guarenteed and others like playerposition not



Specs: AMD Athlon 1800, 256 DDRRam 266mhz, 80GB HD 7200rmp U133, Geforce 4 Ti4400 128mb
Bulleyes
22
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 18th Apr 2004 18:26
The principle is, don't use guaranteed flag if it is not really necessary. Guaranteed flag instructs Directplay to use TCP as oppose to the lightweight UDP. The overhead of TCP is resending of packet, packet received acknowledgement, etc. (Read more on TCP/IP if you wanna no more.) Thus, you only use guaranteed packet if it is really necessary. You need to justify the necessity based on the nature of your game. For a client/server game, it constantly update the game state to all the clients, thus a lost packet is not a big deal as it will be fixed in the next update.

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Mussi
22
Years of Service
User Offline
Joined: 27th Jan 2003
Location: Netherlands
Posted: 18th Apr 2004 19:20
I know how connections work. I forgot to tell using peer-2-peer mode



Specs: AMD Athlon 1800, 256 DDRRam 266mhz, 80GB HD 7200rmp U133, Geforce 4 Ti4400 128mb
Bulleyes
22
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 18th Apr 2004 22:17
The beauty of UDP is more flexible, and it gave you a finer control to it. This also means that you can implement your own guaranteed delivery scheme on top of it. But at the same time, it means more work, so you need to judge it yourself based on your game requirement. Frankly, I never bother about using UDP or able to appreciate the beauty of UDP until I start coding my own multiplayer game and start researching on various techniques used in a network game.

If you are interested, we can chat online and thru instant messenger. Maybe we can share our ideas.

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Mussi
22
Years of Service
User Offline
Joined: 27th Jan 2003
Location: Netherlands
Posted: 18th Apr 2004 22:37
I've some experience with multiplayer coding so I might be able to help ya, add me to msn: [email protected]



Specs: AMD Athlon 1800, 256 DDRRam 266mhz, 80GB HD 7200rmp U133, Geforce 4 Ti4400 128mb
Tywald
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sweden
Posted: 20th Apr 2004 11:13 Edited at: 20th Apr 2004 11:17
Bulleyes:

If i understand what you´re saying, you want to the "HOST" to launch a server and play on it while it´s active. Just like in most FPS where you can launch a network server and play on it at the same time.

Since the server will create a net player when starting a netgame the "Host" player normaly that player.
What you basicly do is to treat that player as if it was like a "Net Player" that connects to the server. Since the "Host" player is playing on the Server that player doesn´t need to send data whit the network but can instead write its inputs directly into a memblock.
After that process, the Server will run the network code and gather all the net messages from the other players. While in that state it will also look in the memblock that the "Host" player has written into and use it. After that, the server do all the calculations and starts to send the data back to the players. It also writes the "Host" Players data into a memory block.
While the data is being sent to the other players, the "Host" player sees if it has got a message from the server (A simple flag would do the job) and use the information in the memblock to render the scene.
In short, the difference betwen the "Host" player and a player connected to the server is that the "Host" player is running the server part betwen sending data and waiting for data.

Look into the Code Box for a simple pseudo code. I have not tested this theory yet...

- Tywald

Edit:
Forgot to add, the game routine and code looks like the same on both the "Host" player and "Client" player but the "Host" has the extra job to run the Server code.
Bulleyes
22
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 21st Apr 2004 09:09
@Tywald:

Yes, you got my question entirely correct! Hmmm.... I will look into your approach, it sounds feasible. But I haven't think of it thoroughly yet. Thanks a bunch!

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/

Login to post a reply

Server time is: 2025-05-31 00:09:23
Your offset time is: 2025-05-31 00:09:23