Online Multiplayer (its possible(maybe))

(Blender_owl) #1

heres how

Online gaming design

One of the things that game blender is lacking is an online multiplayer engine. This document presents a theory on how to program one . I’m not sure if python can support. You will need a winsock control or something similar.

Note this does not contain code on how to do it but a theory on how it works.

Client 1 sends information to Client 2 about what it did. This includes the client’s 1 player position, stats, change in level caused by client1. So basically it sends everything that happens to Client 2.
Client 2 also sends all its information to Client 1
After the data is sent to the other client computer, the game will be updated based on the information sent.
This happens every frame so that the clients are in sync with one another

Here is a basic example.
Client 1 sends this information to client 2 every frame then updates it self:
UserName = Client1
uHP = 50
uPlayer LX = 100 (L stands for loc or location)
uPlayer LY = 200
uPlayer LZ = 100
uPlayer RX = 100 (R stands for Rot or Rotation)
uPlayer RY = 100
uPlayer RX = 100
uExit = False (this checks if the player has disconnected )
uFire = True (has the player fired a bullet if so update creating a bullet on the client 2)
uBull LX = 100
uBull LY = 100
uBull LX = 100
uBull RX = 100
uBull RY = 100
uBull RX = 100
(create a new bullet if the bullet before it still exists. N is an integer. This integer increases by one every time a new bullet is created so that it has a different name from the previous)
uBull(n) LX = 100
uBull(n) LY = 100
uBull(n) LX = 100
uBull(n) RX = 100
uBull(n) RY = 100
uBull(n) RX = 100

As you can see this is a basic game but a lot of data has to be sent. The “u” in front of all the properties being sent is a variable that stores the clients user name so that the properties don’t have the same name as client 2. When the data is received by client 2 it updates it self and sends its info to client 1. This is a loop that goes on forever until some exits.

But before the two clients can start sending information back and forth between each other they need to know a little about each other.

First they need to know where each other are (IP address)
Where the active folder is (where the update information is sent)
What port is open (so that update information is sent)

Once that information is sent then the computers can start sending information to each other.

IP Address:
What is it ?
An IP Address is the location of your computer on the net.
Why do we need it ?
With out it the two clients would not know where they could find each other.

What is it ?
A Port is like a door to your computer.
Why do we need it ?
Once the clients have each others IP addresses they know where they are but still cant send information to one another because they don’t know which port to use. You should use a port number higher than 5000 because a lot of programs use different ports and if you use the same one as another program then it won’t work.
Active Folder
What is it?
It stores all the update information.
Why do we need it?
This is where all the update information is stored and read form. It is imperative that the right path is used or errors will occur.

(saluk) #2

I’m already doing this with python, sockets, and my object system I created for the level editor. It’s not perfect, and I haven’t officially released it yet, but I’ve been planning on getting it out there for quite some time. If you ever see me in irc, pm me and I’ll run the server for you and give you a link to try it out. The official release should be from one to two weeks.

By the way, the server code supporst a theoretical unlimited number of players, and the game code is flexible to be able to support just about any kind of game.

(calli) #3

Saluk: Are you using UDP or TCP?

My own experiments with UDP were quite promising in a LAN (Poor mans Cave for example).

Would love to have a look at your stuff!


(saluk) #4

Actually I’m using tcp. It’s a bit slower than UDP but easier to deal with. From current tests the lag is not bad at all. I want to release my stuff but it’s just not ready yet. You can play around with it though if you ever see me in irc (I’m usually in the blendergames chat.)

(calli) #5

Hmm, never got TCP to work so far :wink: I think UDP is easier, Fire and Forget…

Carsten looks for Saluk in IRC

(Blender_owl) #6

tcp allows you to send more data

(smn) #7

i’m currently developing a multiuser server for a school project here in the netherlands (HvU),
blender was considered as a possible client (we’re developing a game to show off the capabilities of the server) but went ahead with Shockwave3D for now. I’m still interested in getting it working with blender, I doubt it’ll be much of a problem. The server I’m developing does TCP & communicates XML and it’s quite speedy! I tried some stuff with sockets in blender & python but got some problems with threading & stuff. That’s pretty much just because of my lack of python experience. some day… some day…

hoping to see some of saluk’s stuff sometime.

(calli) #8

Wil I meet you guys next weekend? Maybe we can have then or after the show a chat about that topic. I am always interested in hacking stuff so that it does things it was nerver meant to do :wink:

I was experimenting lately with the code and finally found a possibility to have network functionality without the need of external python modules to store the sockets.

I also experimented with a kind of gateway from IP to BlenderMessages to make it reusable.


(smn) #9

i’m afraid I won’t be able to come,…
helaas …


(saluk) #10

I wish I was going :frowning:

How would you not use an external module? I’m very curious about this.

Hope to put up a demo sometime either this weekend or next, it would be cool if you guys at the meeting could all connect and try it out!

(calli) #11

I meant you don’t need a module to store the socket globally during runtime.

I guess someone (possibly Strubi) at NaN heard my moaning. So it seems that since 2.25 you can store all kind of python objects into the GameLogic Module. Even Sockets (which I tried before), so the need for an external module is not given anymore.


(smn) #12

I don’t follow, it must be my lack of python knowledge.

what is the benefit of storing thse objects in the GameLogic module?
how is it different from just importing the Socket and opening it?


(saluk) #13

Ah, right. Darn, I thought you had solved my distrobution problem :frowning:

Anyway, this feature has been available for a while, and my thingie makes heavy use of storing stuff in GameLogic (and I’m using 2.23).

(calli) #14

You dont want to open the socket every cycle of the game engine I guess? And there is no possibility to keep the Socket between two game engine cycles. The Python interpreter is “clean” every time you enter a script. So we do:

GameLogic.achoosenname = “I will exist during runtime”

When I first experimented with UDP in Blender you could have global vars, this was then dropped, I used then a externam python module to store global stuff (it was possible to store simple variables, but no sockets for example in GameLogic at this time).


(smn) #15

I see! understood, that’s certainly better!

I’d love to start coding python in blender now but I’m working on Shockwave3D at the moment. I’m using some python (jython) with the server though, it’s gonna be pretty sleek :slight_smile: