Developing a MMORPG using Photon Unity Server
Abstract
This paper will explain how multiplayer can be implemented using Untiy as game engine and Photon’s networking functionality. The main purposes of this is to offer info about implementing a dedicated server, connecting clients to it, spawning and synchronizing virtual players on the network.
Unity and Photon Server
Unity is a cross-platform game engine developed by Unity Technologies, which is primarily used to develop both three-dimensional and two-dimensional video games and simulations for computers, consoles, and mobile devices.
Photon is a on-premises real-time socket server and cross platform multiplayer game development framework that is extremely fast and very simple to use.
![](public/resources/photon_server_architecture.png)
Protocols of Photon Server
The transfer protocol is very lean and slim. Photon wraps up the networking layer of each client platform for you. Have your game clients communicate cross-platform and across protocols. Put your data in hashtables and just send it. Photon does the de-/serialization, you dont!
Download server sdk and prepare structure
Photon is extremely easy to install and start. The SDK includes ready-to-use binaries which can be up and running within 5 minutes. The Photon Server SDKs are available on the official page and comes as self-extracting executable.
The server package ca be extracted to any place - preferably an empty folder prepared beforehand. The extraction creates several folders. The "deploy" folder contains the binaries. This is what you need at least to run Photon. The folders doc, lib and src-server (applications) are for development.
Starting Photon
In the "deploy" folder you will find a folder per application and some folders starting with "bin". Open one of these two:
In either folder, you will find the actual Photon executable. You can start this with command-line arguments or you can use PhotonControl. Start PhotonControl.exe and confirm the admin rights for this application. They are needed for the option to setup Photon as a Service.
![](public/resources/photon_control.png)
Build server application
Using Visual Studio, create a new class library project MyServer. After this is important to add references to ExitGamesLibs.dll, Photon.SocketServer.dll, PhotonHostRuntimeInterfaces.dll and loggings dll's log4net.dll, ExitGame.Logging.Log4Net.dll .
Next step is to create an class that inherits from Photon.SocketServer.ApplicationBase. This class is the core luncher of the server and contains a reference to log4net object that will be used in logging. Every client request is handled by an special class inhterited from ClientPeer.
Operation concept
The server project deal with game logic of every client, chat operations and game world. The game logic defines how a client can interact with the server. It implements operations, events, and anything that the server does by itself.
An operation is Photon's equivalent to a remote procedure call. Photon clients use operation calls for anything they want to get done. Operations and all of their parameters are defined in the PhotonMMORPG.Common project. Clients can call any operation by setting up a hashtable with keys and values fitting the operation's conventions. The client and server frameworks take care of serialization, transfer and deserialization.
![](public/resources/operations_responses.png)
Event concept
Photon Events are messages for clients. Each event is typed by a byte code and carries game updates. Unlike operation results, a received event is most likely caused another client's operation call. This means: Events might arrive anytime. Lite sends events when someone joins or leaves a room.
Build client application
Using the free license we can support from 1 to 100 concurent connections (players that are connected at the same time). To establish a connection we must add Phton3Unity3D plugin as reference to our client project and then using the PhotonPeer we can connect to server address.
The game is composed by scenes and every one will use the instance of PhotonPeer that was specify above to send the catched inputs. Also it has the responsabilty of handling the server responses and perform transformations over the game state.
Game State
The game state is a snapshot of the game at a particular instant of time. This includes the position of the PCs and the NPCs as well as the state of the mutable objects. Immutable objects are generally not part of the game state, and are typically installed as part of the game client software, and updated through software update mechanisms. The game state can be changed through the following interactions between game objects
The game state for a MMORPG should be persistent so that the user experience is carried over seamlessly across dierent login sessions. At current point game state isn't persistent
Game scene
The most popular online multiplayer games belong to a group of role-playing games (RPG). In general, the RPG involves a selection of fantasy characters that will delve into the game world and explore its content. The game character has a unique history and features based on the storyline of the game. Each character may belong to a particular race such as Elf, Orc, Undead or Human and plays a reserved role in the game world.
A combination of online multiplayer game and role-playing context results in a concept of a massive multiplayer online role-playing game (MMORPG). Every operation performed by client will be procesed by server and synchronized to all participants.
Character input and animator component
The player will control his own character and based on server decisions will modify the game state as we told. Every active character has an movement script and there in a loop will be waiting for movement inputs. This script allow the player to use the WASD and arrow keys, a controller pad or other device to move the player.![](public/resources/move_animator.png)
The Animator component is used to assign animation to a GameObject in your scene in our case to character gameobject. The Animator component requires a reference to an Animator Controller which defines which animation clips to use, and controls when and how to blend and transition between them.
![](public/resources/animator.png)
Conclusion & Future considerations
The traditional approach to host an MMOG is a client-server architecture. This,however, provides a single point of failure, increases latency and can cause possible bottleneck. At a higher level, this consists of a single server connected to one or many clients over the Internet. More important the players do not need to know any information of the game universe outside their area of interest. This lead us to a new approach : adapting the Client-Server architecture to P2P one.References
- Photon Server Intro
- Photon Server Intro , by Photon
- Doctoral thesis
- ARCHITECTURES AND PARALLELIZATION TECHNIQUES FOR 3D MMO SERVERS by Asavei Victor
- MMORPG Architectures
- A Survey of MMORPG Architectures by Sakib R Saikia