Hi there,
This is another template for network multiplayer. This is like a deathmatch (actually not a FPS, sorry)
I made a lot of improvements over the first version.
Server and client are in a single file (but in different scenes)
This version uses only non-blocking sockets. So, it does not freeze blender and don’t need multithreading
Interface to choose run server, or type server IP address and run client
Real multiplayer. 1, 2 3,…, 20, 400 players can join the game. It is limited only by server memory and network lag. You can use this in your MMORPG ( it’s a joke !!! Check posts below)
On screen message log
What is missing:
Detect clients disconnection to remove avatars from game. (I already did it, but the script simply disapeared :()
Detect when client fall from arena and send a “frag” message (and count “frags”)
Some UV scroll on tank movement
How to test (in one single machine):
Open multiple Blender instances with the tank.blend file and position windows side-by-side (you can see 4 blender instances in the pic below)
Run (“P”) the game engine in all Blender’s
Choose one Blender to run server (click “Run as Server”)
Choose the remaining Blenders to run client (click “Run as Client”)
Use WSAD in a client to move the tank. Arrows to aim the turret. Space to shot
See action sychronized in all blender’s
How to test (in a network):
Chose someone to be the server (everybody must know the IP addres of the server machine)
Run Blender (tank.blend) on server machine and click on “Run as server”
Run Blenders (tank.blend) on other machines. Type the server IP address and click “Run as client”
Try a deathmatch (and tell me if it works :o)
I tried to put a lot of comments in the network code to help people understand it. But what people must be aware is that the network code is not the hard part. The most complex task in any networked multiplayer game is to define and control the communication protocol and synchronization messages and procedures.
I wil try make this a complete game
Traceback (most recent call last):
File “NWC_ReceiveState”, line 9, in ?
File “/usr/lib/python2.4/threading.py”, line 13, in ?
from collections import deque
ImportError: /usr/lib/python2.4/lib-dynload/collections.so: undefined symbol: _PyArg_NoKeywords
Compiled with Python version 2.4.1.
Checking for installed Python… got it!
Thanks OTO.
It looks something wrong with your threading module. Well, i am not actually using it (but i forgot to remove the import command from the scripts). I posted a version without this imports. If you can test it again …
Heh, wasn’t able to test it out on my old labtop, but will try it out with my desktop later on. Is this only for network or does it work over the internet too? Haven’t tried that yet either.
Morgade, if it’s not too much of a hassle, would you be able to explain what parts of the code would be hackable to be customized for different multiplayer games.
In particular…
which places send/receive message pertaining to the player
for me it’s working on ubuntu (6.10 and 7.04) with network on LAN …but it’s not “fast” … the animation drops at 15/20 fps with lag with “outside” and “services” using the CPU almost at 100% together … with only 2 clients …
I think that from this, we are long time ago in a galaxie far, far away from having a MMORPG structure …
but it’s a good start … !
Also, the disconnecting feature is VERY important … the whole system is pointless if it’s not able to wipe out disconnected player, at least after some time of idle…
mm… A lot of things can be happening. Coding a network game server requires a lot of hacking. It’s needed to optimize sockets buffering use, message sending interval, position interpolation in clients, delay workarounds, etc… The CPU charge could be saved if you use a lower buffer size in the recv operations (try changing it to 512 instead of 4096 in the ReceiveState and ReceiveInput scripts). The lag could be caused by network problems, or lower operation system UDP datagrams queues (causing message dropping). Or even you are noticing the LogicTicRate set to 30 (state being synchronized only 30 times per second to avoid network flooding). Finally, check if some unexpected error are being printed every frame in the console, making everything slower.
The MMORPG thing in my post was just a joke. A MMORPG server is a real complex system. You can create a MMORPG client with Blender, but i doubt someone can create a robust server. The server could be more easily created in something like Java or C++ (and it sill can use Bullet physics).
I will try to add this soon. It’s just an Always sensor pulsing every 3 seconds to a python script that checks the state of all TCP client connections, and remove objects related to clients with invalid TCP state.
is it open source, or do you want royalties to further development? (beer? pizza? cake?) :eyebrowlift2:
going to check thouroughly when I get home from work, but eh, do you mind if I cannibalise the code and game mechanics for another project? (off course I’ll make any cough improvements cough on the network engine available).
yes, I know, I’m sucha a lazy programmer I don’t even take the time to code it myself. :o
(the coughing is mostly due to me not being a good programmer, and that I suppose I won’t be able to do anything but bog the network code down, but at the very least, I’ll give it a try).
The MMORPG thing in my post was just a joke. A MMORPG server is a real complex system. You can create a MMORPG client with Blender, but i doubt someone can create a robust server. The server could be more easily created in something like Java or C++ (and it sill can use Bullet physics).
well … I understood that =^^= …
From my point of view, a MMORPG is not only a problem of network coding, but also a content production question… it needed millions of bucks to blizzard to build WoW, so of course, we’re not playing in the same court…
For the multiplayer server part, I think it could be done in python also, and maybe the BZoo project could give some ideas. (don’t know if it’s still alive …)
Here, I tried to reduce the buffer but it didn’t change anything… and no error in the console…
I understand this is some hard work, it’s why I did reply with what I found on my systems (and the fact that it works with lan on linux)… I’ll look further to see if another machine has the same problem as server, as I tested this on an AMD64 build that I don’t trust completely.
Just poking my head in to tell people that it seems to be working, for me, running 6 clients on the same computer gets a little laggy and weird but it passed the crucial test: it didn’t crash my old’n buggy computer
Open Source. You can send me some bucks if your game become the next WoW
Go ahead.
I know ! I emphasized the joke because suddenly i realized that most people reading the post could take it serious ! :o
Mmm… I know it’s like to argue about religion, but actually I’m not a Python fan. I think that static typed languages (like C# or Java) are better than dinamically typed (like Python) to implement big projects like a game server.