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.

Newcomers DBPro Corner / How do I make a "multiplayer game"

Author
Message
retardnewb17
13
Years of Service
User Offline
Joined: 6th Oct 2011
Location:
Posted: 25th Mar 2012 22:19
I have tried to make a multiplayer very long, and I just don't understant how... I have watched tutorials about making multiplayer in dbp, but I just somehow can't make any kind of connection.
Pleace help me! xD
Millenium7
19
Years of Service
User Offline
Joined: 13th Dec 2004
Location:
Posted: 26th Mar 2012 14:14 Edited at: 26th Mar 2012 14:19
I'm not going to post you a tutorial, there are plenty of them out there. I first want you to get your head around how the concept works

To keep it as simple as possible I recommend downloading and installing MultiSync, this is a 3rd party multiplayer plugin for DBPro and it's more efficient and better to use than the built in DBPro multiplayer system

The concept of multiplayer is this
One player is the server, they will send/receive information from all other players
Everyone else is a client, they 'only' connect to the server, they do not connect to any other player. It's up to the server to tell each player about all the other players in the game.
Make sense?

Whoever is going to be server must 'create the game', this allows clients to connect. The server needs to have ports opened, but to keep this simple ignore that process for now

Client's need the IP address and port number of a server. Forget about the potr number for now but you'll need to set it later. Have each client 'connect' to this IP address. Before the client actually 'joins' the game, the server must 'accept' them. I think the command for multisync is 'net player joined()'
So to recap
Server: start game
Client: connect to IP
Server: Every loop, check if a new player has joined, if they have they'll be 'accepted'. If you don't check they won't be accepted
Client: once 'accepted', has now joined the game and can send/receive information

Then you just need to code in sending data, and receiving. Look up tutorials to learn more
edit: it's important to know that you don't actually send 'commands' to clients. For instance you cant send "paste image 1,0,50" to a client. You send strings/integers/floats/etc. So in order to tell a client to 'paste image', you might first send a string that says "img" followed by "1" followed by "0" followed by "50".
Upon receiving this command you check if it was a "img" string, which means paste an image somewhere, according to the data which comes after it. It's up to you to code in how the data is deciphered
retardnewb17
13
Years of Service
User Offline
Joined: 6th Oct 2011
Location:
Posted: 26th Mar 2012 19:32
I have no idea how to use these third party things or multisync...
xD
erebusman
13
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 27th Mar 2012 15:07
Millenium7 : That was a nice & easy to understand break down . I bookmarked this for later use when I want to think about multiplayer integration to my game(s) as this helps set the state for deeper understanding!

Thanks!
Millenium7
19
Years of Service
User Offline
Joined: 13th Dec 2004
Location:
Posted: 27th Mar 2012 17:36
all required documentation to install multisync should be available here http://forum.thegamecreators.com/?m=forum_view&t=99188&b=5

There is a lot more to multiplayer. For instance the server/client method is not the only method, but it's by far the most common and there's no point getting bogged down with the details

Following on from my original post.....
(don't worry about this until you can successfully connect to a game and send/receive some data)
With the server/client method, keep in mind that clients do not send any information to other clients. They only send it to the server. MultiSync does not automatically forward that information onwards. I.e. let's say there are 3 players in the game
Player1 is the host, and players 2/3 are both clients.
The model would look a bit like this



If Player1 sends a message to all, then both player 2 and 3 will receive it. If Player 2 sends a message to all, then' only' player1 will receive it, because messages ONLY go to the server from a client! doesn't matter what player number you specify
For some information this doesn't actually matter - and i'll explain why shortly - however for certain packets such as 'chat messages' this is a problem, since player2/3 won't see each others messages. To overcome this the process must be
Player2 sends to Player1 -> Player1 receives message, sends a copy to 'all' players -> Player2 & Player3 receive message
There's a more efficient way to do this (player2 doesn't need to receive his own message again) but for the sake of simplicity let's stick with this for now

This is fairly easy to implement. On the server side all you need to do is check for incoming messages, and anything received is sent out again
i.e.


Keep in mind that if you are implementing a chat system, and using the method above, you need to make sure that whenever a chat message is sent from the server, the server will immediately display it's own messages and not wait for a reply from the client (since the client should not be sending chat messages back to the server again, otherwise it'll be bouncing back n forth forever)
However on the client side, they should not show their own messages immediately, instead they should only show what is received back from the server. Otherwise they'll end up showing their own messages twice (once when first sent, once again when the server sends it back to them)

Some data does not need to be 'sent back' immediately, such as player positions. These should be sent from the server constantly, so any client's should always be receiving the most up to date information anyway and there is no need to get an immediate bounce-back on this sort of information. Chat messages however are different, because they are unique and only sent on occasion, they need to be bounced back from the server to all clients. Hope this makes sense

Login to post a reply

Server time is: 2024-11-23 20:24:39
Your offset time is: 2024-11-23 20:24:39