Game Development Community

dev|Pro Game Development Curriculum

Proof of Concept: Adding Networking to Single Player Games

by Demolishun · 03/05/2013 (10:18 pm) · 10 comments

Proof of Concept: Adding Networking to Single Player Games
RPGs are one of my favorite genres in games. I absolutely love the open world feel of Morrowind and Oblivion (have not played Skyrim, someday). So these are single player games that I can go and role play a character completely independent of the main story line. Why add networking?

Community engagement.
So you are playing an awesome RPG like Oblivion. You do something really fun and you get all excited about the experience. Then you realize you are going to have to quit or minimize the game and open up a browser to share your experience on a forum. Often times you have to dig to find the thread that usually talks about this. So you either stop playing now, or you try to remember to do this later.

Fortunately for Oblivion you can grab a mod (PC version) and add a logging feature. Outside the game you can later grab the text file with the log and find your entry and paste to a forum or blog. So why not get rid of the middle man? Why not add features to the game that explicitly allows IRC, blog, forum, Facebook, etc blogging?

This is an idea I have been toying with. I even have a plugin that is mostly working for OBSE (OBlivion Script Extender). My plugin uses the Boost framework for threading and network programming. I create a UDP port and communicate over the network connection using JSON. The intent is to have the Oblivion plugin create a port on localhost. Then an external program can talk to that port and use whatever application framework you desire to communicate to the outside world. I am using Python for this purpose.

The cool part is you take a proven title and test proof of concept ideas out with it. So you have a ready made world, ready made game play, etc. You can really mess with changing the way you interact with the outside world with the game. This is something we kind of take for granted with Torque. We already have these kinds of interfaces if we choose to use them.

Conclusion
This idea has been bugging me so much that I need to get it out of my mind. So I am going to finish the features the plugin needs, test out some game play features, and release the code to the OBSE community.

I think it can be helpful to be able to test out ideas in a fully complete game. Especially technologies that the game might not have originally had. It is also an excuse to write interesting mods and mess with some white-hat hacking type software. And it is fun.

Stay tuned, my next blog may be from inside a game engine. Who knows? Oh, and there might be pictures too!

About the author

I love programming, I love programming things that go click, whirr, boom. For organized T3D Links visit: http://demolishun.com/?page_id=67


#1
03/06/2013 (2:55 pm)
Frank,

You and I are of the same ilk. I too enjoy the large open world single player RPGs. To me this sounds like a really cool idea. I will keep watching to see how it goes. Good luck.

Ron
#2
03/06/2013 (8:28 pm)
Thanks Ron.

One thing that working with Oblivion is that players are making way better content than the original game itself. This tells me that a game can live way beyond initial release if you engage the community. I know I have personally bought more than one copy just because of the modding features.

Going a step further is engaging the community with modding AND with simple interaction in a single player game. Apparently people tend to play RPGs (even MMORPGs) alone, but together. Yes they sometimes come together to take out a big baddy. But there is a phenomenon where people prefer to play alone, but occasionally interact. My experience with this phenomenon in my own gaming reflects this. One thing Oblivion is missing is that: "Hey! Look what I did!" feature. I think this is where Steam shines for single player games. They are doing the stat bragging for games that support it.

Now going one more step. I had an idea where you could create items, weapons, etc and the game could choose the item based upon unique stats, powers, etc to be included in an online item database. As different people played these items could show up in random locations during gameplay of people. So the database could act as a unique item database mods can use to enrich the game. Also, whole characters that complete certain tasks could be put in such a database. So someone could potentially meet a character somebody on the other side of the world played as in the game. A sort of random encounter type thing. So someone could run into some ultra powerful wizard called Bob. If IRC/blogging were enabled as well people could be like: Did you see Bob? That character is awesome!

Anyway, I am rambling, but you get the idea of how adding multiplayer feedback to single player could make for some awesome gameplay.
#3
03/12/2013 (10:31 am)
The more I work with C++ the more I appreciate the crap Python does for me.

  1. Time to setup C++, JSON, UDP, and Threading: 10 to 15 hours (kind of rusty)
  2. Time to setup Python, JSON, UDP, and Threading: 2 to 4 hours (using a framework I had never used before)
  3. C++ : most time spent doing data conversion from char * to unicode and in the JSON library to understand how it works
  4. Python : most time spent solving problem
  5. C++ : most appreciated library: Boost
  6. Python : most appreciated library: Not sure I can choose, for networking it is definitely the simplicity behind Twisted
Fortunately once the OBSE plugin is done most work will be in game script or Python.

Also, the C++ interface to OBSE is somewhat incomplete. So it really makes me appreciate a code base like Torque.
#4
03/20/2013 (11:57 am)
Getting close to having more info on this. I am refactoring some of the code to make it cleaner and working out some of the features. Learning a lot about boost threading and async timers and such. I am making sure all communication to and from the game are async in nature. So there will not be an immediate response when the engine is queried. The protocol will be determined by the script writer in the end. I am standardizing how to build a packet, but that actual JSON data structure sent will be definable by each script mod.
#5
04/01/2013 (10:16 am)
Initial testing is working. I am able to send JSON messages to the game, it decodes them properly, and acts upon the messages in game script. My first operational test was sending the form ID of the vamp feed sound every five seconds. Upon receiving this form ID the game would play that sound.

This leads into my first practical use for this networking feature. I am going to make a web site on my local lan that sends UDP messages from PHP to the computer with the running game. Then I can sit in the living room with my kid playing the game and use my phone to trigger events in game. Of course they won't know I am doing this. So periodically enemies may appear, or the random phrase "You should have paid the fine!" will occur.
#6
04/04/2013 (8:10 pm)
Haha! I am testing this tonight! I got my CodeIgniter website sending play sound commands to the game. I can sit and watch my kid play and I will periodically play various sound effects initiated from my phone. Eventually I will add character spawning and stuff, but for now it is time to play!
#7
04/14/2013 (5:48 am)
Sounds funny.
Could also be a way for parental control in that way, that you can receive a screenshot on request.
If the shorty is looking on a females boobs all the time, you push the button and let them explode =D

Me and my buddy started a project recently. Guess...
Multiplayer for The Elder Scrolls V: Skyrim.
We are about to explore SKSE (like OBSE but for Skyrim) right now. You know about this well documented piece of software ;)
We are going to build it as an SKSE Plugin (c++). For the network part we are going to use Boost:Asio.
The goal is to build a coop-mode. So 2 or more players can walk through the story together.
The alternative goal is an arena-mode, where players can fight each other.
We are at the very beginning.
Did you publish your OBSE-Project right now? Surely we can learn from it...
#8
04/14/2013 (10:00 am)
I read somewhere that there is a lag in Skyrim scripts. It might affect how quickly you can update positions and state in game, YMMV.

There is already a network plugin for OBSE: cs.elderscrolls.com/index.php/OblivionOnline. This may give you some ideas at it is more geared toward interaction between players.

My plugin: xp-dev.com/wiki/186953/Homepage is not geared toward interaction. I am guessing it would not be fast enough but you are welcome to try it out. Also note that the opcode range is selected for my plugin. So don't use that range in other plugins for Oblivion. Also I would prefer you do not distribute copies of my plugin in binary form so there are not multiple versions out there.

Currently I do not have a binary on there so contact me (me __AT__ demolishun __DOT__ com) and I can send you a dll for Oblivion. I am still working out the details on the xp-dev pages to release this plugin.

Some architecture details of the plugin:

  1. Uses Boost::threads and Boost::asio.
  2. Implements a UDP port.
  3. Uses JSON for data format.
  4. Converts to and from OBSE maps, arrays, and data types.
  5. Does automatic conversion of form types.

If I were to redo this plugin I would probably research using Boost::json. I used a different library that works, but was not very intuitive. Also, I do conversions for JSON unicode which are a pain in the arse. JSON is supposed to be transferred in UTF-8 format so I wanted to support that. However, the facilities to convert are also a pain in the arse. If you know some better ways than I do for those conversions please let me know.

I also ran into some strange issues with Boost::deadlinetimer and Oblivion. If I defined a deadline timer in the main thread code of the plugin Oblivion would fail to start up correctly. It was very weird and I finally got it working by instantiating the deadline timer inside my thread that handles network io. You will see how I did that in the code.

Anyway, I will be doing another blog on this after I make a video of using it to harass people playing Oblivion. Feel free to email me questions at the address I listed above.

Edit:
Plugin has been uploaded in binary form on Tesnexus.
#9
04/15/2013 (1:06 pm)
I read somewhere that there is a lag in Skyrim scripts. It might affect how quickly you can update positions and state in game, YMMV.

We'll find out soon. I hope SKSE can speed this up.
I think we'll have a first version with some players just jumping and moving around next month. But if the engine is not performant enough we lost =S

Man. The OblivionOnline project is huge. They implemented a lot of things by their own. I'll use SKSE excessive =)
If someone can't find the code: svn
Thank you for this info. There's a lot to learn from this project -- especially from the source files ;)

I never meant to make a full featured multiplayer mod. I initiated this project for self education purposes and just for fun. But if the base proves performant and stable I'll surely not stop playing with this baby in my IDE =)
#10
04/15/2013 (1:34 pm)
Even if it is fast enough to have 2 players with nothing else it could be possible to do an arena mod. I thought I might be able to pull that off with my mod. With added support for communicating to a server (external app) then people could do bout matches with different characters in such a mod. So it really depends on how much performance you really need.

My focus was simple interaction and additional modding resources. I would probably structure things a little different for a multiplayer mod. One thing I thought about was grabbing the network code out of T3D to handle the networking side. It is high performance. The bottleneck there would be how fast the script can loop and update positions. The security issue would be peer to peer trust, but since it is more about proof of concept than production code that does not matter.