ES4 Manual
ES4 Manual
Table of Contents
Part I Server Overview 4
1 ElectroServer...................................................................................................................................
4 Overview 4
2 Common Applications
...................................................................................................................................
of ElectroServer 4
Real-Time Isometric
..........................................................................................................................................................
Environment 4
Lobby and Game
..........................................................................................................................................................
System 4
Audio/Video Streaming
.......................................................................................................................................................... 4
3 Server Versions
................................................................................................................................... 5
Standalone Mode
.......................................................................................................................................................... 5
Distributed Mode
.......................................................................................................................................................... 5
4 Web-based Administrator
................................................................................................................................... 6
Part II Installation 6
1 Hardware ................................................................................................................................... 6
2 Operating System
................................................................................................................................... 7
Windows .......................................................................................................................................................... 7
OS X .......................................................................................................................................................... 8
Linux .......................................................................................................................................................... 8
Other Unix .......................................................................................................................................................... 8
3 Initial Configuration
................................................................................................................................... 9
Registry and Standalone
.......................................................................................................................................................... 9
Gateway .......................................................................................................................................................... 9
I
II ElectroServer 4 Manual
Persistent.........................................................................................................................................................
Rooms 14
Create new Persistent .........................................................................................................................................
Room 14
Restart Server
......................................................................................................................................................... 14
Part V Extensions 21
1 Types of Extension
...................................................................................................................................
Components 22
Plug-ins .......................................................................................................................................................... 22
Managed Object..........................................................................................................................................................
Factories 22
Event Handlers.......................................................................................................................................................... 22
Login Event
.........................................................................................................................................................
Handler 23
Logout Event
.........................................................................................................................................................
Handler 23
User Variable
.........................................................................................................................................................
Event Handler 23
Buddy List.........................................................................................................................................................
Event Handler 23
Private Message
.........................................................................................................................................................
Event Handler 23
Extension.........................................................................................................................................................
Lifecycle Event Handler 23
Audio/Video
.........................................................................................................................................................
Event Handler 23
2 Extension Structure
...................................................................................................................................
and Deployment 23
Extension.xml.......................................................................................................................................................... 24
3 Extension Loading
...................................................................................................................................
and Start-Up/Shut-Down Process 25
4 Extension Reloading
...................................................................................................................................
Process 26
5 Server API ................................................................................................................................... 26
Part IX Clients 34
1 ActionScript................................................................................................................................... 34
ActionScript API
..........................................................................................................................................................
Overview 34
The ElectroServer
.........................................................................................................................................................
Class 34
Requests,.........................................................................................................................................................
Responses, and Events 35
Event Handling
......................................................................................................................................................... 35
Differences between
..........................................................................................................................................................
the ActionScript 2 and ActionScript 3 APIs 35
Commonly Used..........................................................................................................................................................
Classes and Methods 36
Commonly .........................................................................................................................................................
Used Classes 36
Common .........................................................................................................................................................
ElectroServer Class Methods 36
2 Errors ................................................................................................................................... 36
Index 0
III
4 ElectroServer 4 Manual
1 Server Overview
1.1 ElectroServer 4 Overview
ElectroServer 4 is multiplayer server product that facilitates interaction between many connected
users. Having been tested with as many as 200,000 concurrent users, ElectroServer 4 is highly
scalable. In addition to multiplayer capabilities, ElectroServer is used for real-time audio and video
streaming and recording.
ElectroServer works by allowing client applications, such as Flash, Java, or Silverlight, to connect via
socket to it and log in. This connection is persisted as long as the client wants to stay connected.
While connected the server can push data to the client or the client can make requests of the server at
any time.
Developers often find zones and rooms useful. A room is a collection of users that can all “see” each
other. These users can easily communicate to achieve chatting or multiplayer game play. A zone is a
collection of rooms. Chatting can occur as public messages sent to an entire room of users, or private
messages that are sent to one or more specific users in any room. Users can add other users as
buddies. Users are informed when their buddies join and leave the server.
The server is highly extensible using what are called extensions. An extension is a collection of 1 or
more ActionScript or Java files/classes that are used to add more functionality to the server. These
extensions can be used as server-level event handlers, such as the Login Event Handler, as Managed
Objects which come in handy for things like database connection pooling, or as Plugins. Plugins are
run at the server level or at the room level and are frequently used to execute game logic.
The server is configured and maintained via a powerful web-based administration tool. This allows for
management of things like user permission sets, language filters, extensions, and persistent rooms.
For information on more specific concepts or features, detailed articles and tutorials are available on
the ElectroServer website www.electro-server.com.
2 Installation
ElectroServer is a Java application. This means that any computer that can run the Java
Runtime Environment (JRE) 1.6, also known as the Java virtual machine, is capable of
hosting ElectroServer successfully. Windows 98/ME/NT/2000/XP, Solaris, and Linux are
among the supported operating systems.
Read the section relating to hardware to see suggestions on the physical servers you can use or
on your chosen operating system below to learn how to install ElectroServer.
2.1 Hardware
While ElectroServer is flexible and can run on many different hardware configurations, it performs best
when a few things are kept in mind.
Ultimately though, processor speed is the most important item for scalability. In both a standalone
instance and a registry instance, processor speed is number one with concurrency a close second.
When dealing with gateways you can use smaller machines as you can simply scale by adding more
gateways into the mix.
This rule of thumb is far from perfect but it's a good starting point. On Intel or AMD hardware, we
would recommend against more then eight gigabytes of RAM as we haven't seen it give much
improvement but when in doubt, more RAM is safer then less.
If you are running on Sun's Sparc hardware, please contact us and we can work with you to determine
the optimal configuration.
Despite the growing popularity, Windows appears to offer the worst performance with ElectroServer by
a significant margin while the various Unix options all perform well. For the ultimate in performance
and scalability, Solaris on Sparc is the clear choice due to the fact that it supports a great deal more
processors than are available with Intel or AMD systems.
So which is best?
There is no "best" hardware/software platform for all situations but if we were to pick a single
configuration that is both cost effective and performs great in all common scenarios we would suggest
a dual-core Linux box with between two and four gigs of RAM. Increasing the box to a dual-processor/
dual-core system will literally double your performance as well. If growth is important, getting the box
with only a single processor installed and half the RAM is a great way to leave room for growth without
breaking the bank.
1. To install ElectroServer, you first need to download the Windows installer from
http://www.electro-server.com and save it to a known location.
2. Locate the file you just downloaded and double-click it. Follow the series of prompts to complete
installation.
During the installation process you will be asked a series of questions. The most important of these
is if you are installing Professional or Enterprise. If you are not sure which to choose, use
Professional. The rest of the prompts will be defaulted for you; only change them if necessary. One
key thing to remember is the administrator username/password and the web server IP/port. You will
need those to get into the web-based administration panel.
Once the installer completes, you will have finished installing ElectroServer 4 successfully.
3. To start ElectroServer 4, click Start > All Programs (or Program Files) > ElectroServer 4 > Start
ElectroServer.
ElectroServer should start up without any problem. The console window will remain open as long as
the server is running. If started properly, the last entry in the console window will say "ElectroServer
has started successfully". If you install different versions of the server (Registry or Gateway) the
command will be named appropriately but the server will start the same.
2.2.2 OS X
ElectroServer is based on the latest Java platform, 1.6. Unfortunately, Apple hasn't gotten around to
actually supporting Java 1.6 on either Leopard or Tiger. As soon as 1.6 is available, we will provide an
installer for OSX and update this section.
2.2.3 Linux
Installing ElectroServer on a Unix server that supports RPM files is quite simple. The server will deploy
the correct version of the Java runtime for you automatically.
1. To install ElectroServer, you first need to download the RPM installer from
http://www.electro-server.com and save it to a known location.
4. Run the following command, replacing <file name> with the actual name of the file you downloaded:
5. That's it!
The server and JVM will deploy automatically into the "/opt/ElectroServer_<Version>" folder. To start
the server, you simply need to execute "./ElectroServer" (without the quotes) from within that
folder.
To prevent the server from stopping when you close the console, you need to use the nohup
command. It would look like this in that case:
nohup ./ElectroServer &
If you install the VM and the server won't start, you will need to define the environment variable
"INSTALL4J_JAVA_HOME" to point to your VM installation folder.
1. To install ElectroServer 4, download ElectroServer 4 and save it to a known location on your hard
drive.
4. Run the following command, replacing <file name> with the actual name of the file you downloaded:
This will unzip the file and remove the ".gz" extension as it's no longer "gzipped".
5. Run the following command, replacing <file name> with the actual name of the file without the ".gz":
This will extract the server into a sub-directory of your current working directory named
"ElectroServer_<version>". To start the server, you simply need to execute "./ElectroServer" for
Standalone mode, or "./Registry" for Registry mode and "./Gateway" for Gateway mode from
within the folder.
To prevent the server from stopping when you close the console, you need to use the nohup
command. It would look like this in that case:
nohup ./ElectroServer &
This file contains the name of the instance as well as the web server configuration. It's critical that the
web server is configured with an available port and IP otherwise you will be unable to access the web
administration.
2.3.2 Gateway
Gateway instances use their own configuration file in the "server/config" folder: GatewayConfiguration.
xml
Like the registry/standalone configuration, this file also contains a "name". This name is used to
identify the instance in the web administrator.
The file also contains an entry for a pass phrase. This value is necessary for the gateway to log into
the registry server when it connects. This value must match the same value in the registry server
otherwise the gateway will fail to log into the registry.
Finally, the file contains a pair of entries that contain the IP and port of the registry server. These
entries need to be the same as the matching settings in the registry for distributed mode to work.
3 Administration
3.1 Web Based Administrator
ElectroServer comes with a full-featured web-based administrator. Almost all server
configuration and maintenance is done through this tool. This includes managing extensions,
creating server-level plugins, persistent rooms, configuration filters, setting up gateways,
managing license files, and much more.
This section describes the web-based administrator tool and each major section at a high
level. Further details on specific fields can be found in the help text on every page of the
manual.
To use the web-based administrator ElectroServer must be running. The admin is served up
using ElectroServer’s built-in web server. The settings for the web server are the only server
configuration settings that happen outside of the admin. The web server settings are
configured here: [installation directory]\ server\config\ES4Configuration.xml
3.1.1 Accessing the Web-based Administrator
If all server default settings are used during installation, then you can access the admin here:
https://localhost:8080/admin/
Once you arrive at the home page you will be prompted to log in. If you left the username and
password as the default during installation then they are: administrator / password. You will
be immediately warned to change these after logging in.
3.1.2 The Web Admin Sections
This section of the admin is used for general server settings such as thread settings, timeouts,
and licenses.
· Manage Licenses
· Edit Server Settings
· Edit Thread Settings
· Restart Server
· Shutdown Server
By default ElectroServer has a demo license (limit of 25 users, any IP address) installed.
Through this section the properties of all installed licenses can be viewed and new licenses
can be uploaded. More licenses can be installed, but only one license is active at any time.
Once you purchase a license, install it, then use manage licenses to enable the new license. A
server restart is required for a license to become the active license. Inactive licenses can be
deleted.
3.1.2.1.2 Edit Server Settings
The Server Settings page allows you to edit general server settings and communication
settings. These include things like the server name, the IP/combo that the registry uses to list
for gateway connections, and idle disconnect time.
· Server Name
This page displays the current thread settings. They should only be modified by advanced
users that understand what they mean.
· Processor Thread Count
· Minimum Pool Size
· Maximum Pool Size
· Scheduler Thread Count
· Use Executor Filter
3.1.2.1.4 Restart or Shutdown Server
The web based administrator's General Settings menu has options for restarting or shutting down the
server. You may also shut down the server manually by closing its command window, then start it
again later by running ElectroServer.exe.
ElectroServer provides several ways for you to secure your application. This can be done by restricting
access to the web-based admin, restricting what users can do using permission sets, and by using
secure certificates.
3.1.2.2.1 Manage Permission Sets
This section allows for permissions sets to be managed: create a new permission set or modify
an existing one. A permission set is a list of a few dozen actions that a user could possibly
perform when logged into the server. The permission set has a name and then a yes or no
associated with each action. Permission sets are assigned to users when they log into the
server.
To create a new permission set, click Create a new permission set, enter a unique name,
then click Yes next to each permission that users in that set should have. Click Save when
finished.
To edit an existing permission set, click the name of the set, then click either Yes or No on
any permission that needs to be changed. Click Update when finished with this permission
set.
3.1.2.2.2 Manage Web Admin Users
Through this section new admin-level users can be added, updated, or removed. You can
assign major activities that you want the admin user to be able to do such as managing
extensions or managing filters.
To create a new web admin user, click Create a new admin user and enter each of the
following:
· Username
· Full Name
· Password
· Repeat Password
Next, check any or all of the following boxes to give this admin user the privileges needed:
· Can manage users
· Can manage extensions
· Can manage filters
· Can manage persistent rooms
· Can manage stat server
To edit an existing web admin user, click the username, then make any modifications needed.
Click Update to save the changes, or Delete to delete the user.
3.1.2.2.3 Change Keystore Password
This page allows you to change the keystore password. The keystore is where ElectroServer
stores its certificates.
3.1.2.3 Gateways
When run in distributed mode the server is made up of one to many gateway servers and one registry
server. A gateway server manages client connections.
When run in standalone mode the server has a single gateway server and no separate registry server.
3.1.2.3.1 View existing gateways
This section shows all gateways that exist. Click the + symbol on a gateway to view more
information. Multiple gateways are only used in distributed mode, which is an enterprise-level
feature.
When you first arrive at this page in the admin you will see one gateway running called
StandAlone. If you are running in standalone mode, which most developers will, then this is
the only gateway you will ever need. To support more protocols or IP/port combos, you can
just use this gateway and edit it.
When you edit a gateway you can add more listeners (IP/port combos) and assign an expected
protocol to each. To add a new listener just enter the IP or hostname into the empty field, give
it a port, select a protocol (text is the most common), and click save.
This option is only available when running in distributed mode, which is an enterprise feature.
To create a new gateway click on the ‘Create a new gateway’ link. Enter a name for it and the
registry pass phrase. Set the number of connections to the registry to something reasonable,
like 100. Click save.
3.1.2.4 Filters
ElectroServer provides flexible support for flooding and language filters. Filters are used to help
automatically restrict abuse in your applications. The language filters can be used to whitelist or
blacklist word usage. The flooding filters can be used to restrict the rapid firing of messages or too
many duplicate messages.
3.1.2.4.1 Manage Flooding Filters
Through this section you can view, add, and edit flooding filters. You can also edit the default
flooding filter and the default flooding filter settings. Flooding filter settings are used to
determine what actions should be taken when a violation is detected. Please see Filters for
more detailed information.
3.1.2.4.2 Manage Language Filters
Through this section you can view, add, and edit language filters. A Language Filter is either
inclusive or exclusive. If inclusive, all words filtered must be in the associated word list, if
exclusive then no words in the associated word list can be found in the string. Language
filters contain other properties as well. Please see Filters for more detailed information.
3.1.2.4.3 Manage Word Lists
A word list is just a named list of words. A Language Filter must point to a named word list.
You can create or edit word lists through this section.
3.1.2.5 Extensions
The server is highly extensible using what are called extensions. An extension is a collection of 1 or
more ActionScript or Java files/classes that are used to add more functionality to the server. These
extensions can be used as server-level event handlers, such as the Login Event Handler, as Managed
Objects which come in handy for things like database connection pooling, or as Plugins. Plugins are
run at the server level or at the room level and are frequently used to execute game logic.
Multiple example extensions and plugins are installed in the [installation directory]/server/examples
folder.
New extensions can be added by manually placing them into the [installation
directory]/server/extensions directory, or by uploading a zipped extension through the admin.
After the extension has been uploaded a server restart is required to access it.
3.1.2.5.2 Create New Server-level Component
New server components can be created. They include event handlers, such as the Login Event
Handler, server-level plugins, and managed objects. You select the extension name, give it a
name that you will use to access it later, and choose the plugin in the extension that you want
to use. Optionally you can also add some XML that will be used to pass information in at start
up. A server restart is necessary for changes to take effect.
3.1.2.6 Persistent Rooms
A persistent room is a room that is not removed when the user list is empty. Most rooms are
dynamic and are removed when empty.
3.1.2.6.1 Create new Persistent Room
New persistent rooms can be created and published or unpublished at run-time. For
information on all of the room properties see Creating a Room.
3.1.2.7 Restart Server
Most of the settings that you change in the admin will not take effect until the server is
restarted. You can restart the server using this button. TBI
4 Server in Detail
4.1 Chat
ElectroServer 4 provides a very simple, intuitive, and flexible way for users to chat. There are two
primary ways for users to exchange information:
· Public messaging
· Private messaging
4.1.3 Extensions
Public messages and private messages can be captured by server extensions and processed before
being delivered. For example, a message sent in English may be captured by the server and
translated into Spanish before being delivered to another user. Note: in this example, the translation
would need to be implemented by the developer. Other common extensions of chat will expand
abbreviations or comicify profanity. See PluginPigLatin in the [installation
directory]/server/examples folder.
Extensions can also initialize public and private messages. See Extensions for more information.
4.1.4 Filters
Public and private messaging are affected by language filters and flooding filters. See Filters for more
information.
4.2 Filters
ElectroServer provides flexible support for flooding and language filters. Filters are used to help
automatically restrict abuse in your applications. The language filters can be used to whitelist or
blacklist word usage. The flooding filters can be used to restrict the rapid firing of messages or too
many duplicate messages.
A language filter is identified by its name and can be configured in the following ways:
· Language filter name
· Word list – A list of words to use as either a white list or black list. Words in this list must appear
exactly as they are in the list for an action to be taken.
· Root word list – A list of words to use as a white list or black list. Words in this list can appear
anywhere for an action to be taken. For instance, the “f-word" contains four characters that should
never appear naturally anywhere.
· Language filter type
· Exclusive – If this type is chosen, then the word lists are used as black lists. That means that if
a match is detected between what is being filtered and one of the words, then an action is taken.
· Inclusive – If this type is chosen, then the word lists are used as white lists. That means that if a
word is found in the filtered string that is not in these lists, then an action is taken.
· Strip HTML – If this is enabled, then HTML is first stripped from the string to be filtered.
· Strip Punctuation – If this is enabled, then punctuation is first stripped from the string to be filtered.
4.2.1.1 Filter Match During Public Message
The following actions are defined by default in the web-based administrator. These only apply to
public message filter matches and can be overridden during the room creation process.
· Deliver on failure – If set to yes, then a message that fails the language filter check is still delivered.
If set to no, and a failure is detected, the message is suppressed.
· Failures before kick – This is the number of language filter matches that can occur before the user is
kicked. When a user is kicked, he is just removed from the room but not the server.
· Kicks before ban – This is the number of times the user can be kicked before he is disconnected
from the server and banned from returning.
· Ban duration – This is the amount of time (in seconds) the user is banned.
· Resets after kick – If this is set to yes, then every time the user is kicked, it resets the process as if
the user has never been kicked.
4.2.1.2 Filter Match During Login
If the filter finds a match during login, then the user receives a login response informing them that their
login attempt was unsuccessful and told that their user name failed the language filter check.
4.2.1.3 Filter Match During Room Creation
If the filter finds a match during the creation of a room, then the room fails to create. The user is
informed that the language filter identified text that is not allowed.
4.2.1.4 Filter Match During Private Message
If the filter finds a match during the sending of a private message, then the user is informed of the
language filter match. If the Deliver on failure option is set to true, then the filtered message is
delivered anyway. If set to false, any message that is caught by the language filter is suppressed.
ElectroServer allows the creation of custom named flooding filters through the web-based
administrator. When creating a flooding filter, certain parameters can be created to detect flooding.
The flooding filter of choice is applied to a room during the room creation process. The action to take
(such as kicking the user) is also established upon room creation.
4.2.2.1 Filter Parameters
· Filter name - The unique name referenced when applying a filter to a room.
· Maximum duplicate messages – The maximum number of allowed identical messages sent
consecutively to the server.
· Sliding window duration – The amount of time (in milliseconds) used when considering if a group
of messages is flooding. This is used in conjunction with the parameter for maximum messages in
a window.
· Maximum messages in a window - The number of messages allowed during the given interval.
This is best explained by example. Consider that the sliding window duration is set to 1000ms and
maximum messages in a window is set to five. If a user ever sends five messages or more within a
1000ms duration, then it will be considered flooding.
4.2.2.2 Assigning a Flooding Filter to a Room
When creating a room via web-based administrator or from a client, a flooding filter can be optionally
selected. If a flooding filter will be used, then the following parameters must be specified:
· Flooding filter name (string) – A unique name that identifies a previously created flooding filter.
· Deliver on failure (boolean) – If true and a failure (flood) is detected, the message is delivered. If
false, and a failure is detected, the message is suppressed.
· Failures before kick (integer) – The total number of failures allowed by a user before that user is
kicked.
· Kicks before ban (integer) – The total number of times to kick a user before that user is banned.
· Ban duration (integer) – The amount of time in seconds to ban the user. If set to -1, then the user is
banned until a server reboot.
· Reset after kick (boolean) – If set to true, then the user’s offenses are erased and reset after kicked,
so the user would never get banned automatically. If set to false then number of times the user has
been kicked is stored may eventually lead to a ban (depending on the ban settings).
4.3.1 Zones
A zone is a collection of rooms. Every room must exist in a zone. A room cannot exist in more than
one zone. A zone is defined by a unique name and has no other properties. A zone is not created by
itself. During the room creation, a zone is specified. If that zone does not exist, then it is created.
Users joined to a room in a zone have access to the list of rooms in that zone.
4.3.2 Rooms
A room is a collection of users. Rooms are most commonly used for chatting and playing games, but
can be used in any situation where multiple users need to interact. Users can exist in many rooms and
many zones. Public messages (chat messages) are sent to a room by users or by extensions. All
users in a room receive public messages sent to that room. There are many events that a user can
receive by belonging to a room. These events are configured by the user during the room join process
and are described below.
4.3.2.1 Creating a Room
There are two types of rooms: dynamic and persistent. Dynamic rooms are more common than
persistent rooms.
Dynamic rooms are created at any time by a user or extension. A dynamic room is automatically
removed when there are no more users in that room. A zone is removed when there are no more
rooms in that zone.
Persistent rooms are created using the web-based administrator and always exist, which is the only
differentiator from dynamic rooms.
Whether a room is persistent or dynamic, its properties are the same and assigned during the create
process. Some of the properties can be modified at run-time.
When a user wants to join a room, the following information must be supplied:
· Room name – The name of the room
· Zone name – The name of the zone that holds that room
· Password (optional) – If the room is password protected, the user joining that room must supply the
correct password
· Receive zone list updates (boolean) – If true, the user will receive updates for this zone when
something notable changes. A zone update is a minimal update sent when one of the following
events happen in the zone:
· A new room is created
· An existing room is removed
· A room’s externally viewable details have changed (name, description, capacity, password
status, user count, description)
· Receive user list updates (boolean) – If true, the user will receive user list updates for the room. A
user list update is fired when one of the following events happen:
· A new user joins the room
· A user leaves the room
· The user starts or stops sending a live audio or video stream to the server. Receiving this event
is configurable - see next property
· Receive streaming events (boolean) – If true, the joining user will receive a user list update event
when someone in the room starts or stops streaming a live video to the server
· Receive user variable updates (boolean) – If true, the joining user will receive user variable update
events when user variables are updated. See also User Variables.
· Receive room variable updates (boolean) – If true, the joining user will receive room variable
updates when room variables are updated. See also Room Variables.
4.4 Extensions
The server is highly extensible using what are called extensions. An extension is a collection of one or
more ActionScript or Java files/classes that are used to add more functionality to the server. These
extensions can be used as server-level event handlers, such as the Login Event Handler, as Managed
Objects which come in handy for things like database connection pooling, or as Plugins. Plugins are
run at the server level or at the room level and are frequently used to execute game logic.
4.5 Security
ElectroServer provides several ways for you to secure your application. This can be done by restricting
access to the web-based admin or restricting what users can do using permission sets.
ElectroServer exposes more than twenty key actions that can be permitted or denied via a permission
set. If a user attempts to perform an action that they are not permitted, then that user is delivered a
server error message indicating that access of the feature is denied.
Here is the list of actions that can be permitted or denied through the use of permission sets:
· Create user variables
· Update user variables
· Delete user variables
· Create rooms
· Join rooms
· Leave rooms
· Change room details
· Create room variables
· Update room variables
· Delete room Variables
· Add operators
· Remove operators
· Invoke room plugins
· Invoke server plugins
· Send public messages
· Send private messages
· Kick user
· Ban user
· Kick users (server level)
· Ban users (server level)
· Kick users without operator status
· Ban users without operator status
· Add operators without operator status
· Remove operators without operator status
Note that without operator status permissions allow users who are not operators themselves to kick or
ban other users. Similarly, the add/remove operators without operator status permissions will allow
non-operator users to give themselves operator status and remove it from other operators. Use these
without operator status permissions with extreme caution.
When a user joins a room that user specifies if they want to receive Room Variable Update Events.
The default is to receive these events. All users that have indicated they want to receive these events
are given the list of room variables when they enter and receive events when a room variable is added,
updated, or deleted.
Plugins can implement a Room Variable event handler so that they can tell when a Room Variable has
been modified.
User Variables of a user are seen by other users in the same room. Users in that room can receive
User Variable Update events when User Variables are changed. See Joining a Room for more
information on configuring the User Variable Update event.
5 Extensions
When developing multi-user applications, it’s often useful or even necessary to push some logic to the
server rather than the client. There are many good reasons for doing this but here are a few of the
most important:
· Security – The server is significantly more secure than the client.
· Performance – In most cases, the server will provide much higher performance than the client.
· Manageability – Maintaining code deployed on the server is simpler than maintaining code deployed
on many clients.
· Resolving Conflicts – Making important decisions in one central location allows the clients to agree.
· Maintaining State – Keeping track of the application state ensures that new users entering can
properly view the state.
With all these reasons, it seems that most logic should be pushed to the server, but this isn’t the case
at all. If you push everything to the server, then it will need to do that same work for each client.
Ultimately, while the server might be faster for a few calls, it will get bogged down with many hundreds
of thousands of calls. Because of this, it’s critical to know what should and should not be done on the
server.
Fortunately, there are some rules of thumb on what should be handled by the server that can be used
to make this decision easier:
· Anything that affects the game state directly
· Anything that is critical to game-play
· Any area of an application where clients might disagree on the outcome of an action
· Any area of an application where there are concerns for security
5.1.1 Plug-ins
A plug-in is the most generic and flexible way to add functionality to ElectroServer. Simply put, a
plug-in is a piece of code that can be tied to the server itself or a room and can then be called via
clients to directly ask it to perform an action. As a special case, room-level plug-ins have the ability to
listen to many events that occur in a room such as room variable changes or public messages. These
are the bread and butter of multi-player game development.
Replace the red text with the correct information for your specific database. Merge the
ManagedObjects section of the Extension.xml with the rest of the parts needed for your extension.
Any plugin or event handler in the same extension will be able to use lines such as these to connect to
the database:
If you rename the handle for the ManagedObject in Extensions.xml, you will need to edit the above line
to match.
A login event handler is used to provide custom logic during the login process. The login event
handler is designed to allow a developer complete control over how a user logs into the server.
Multiple login event handlers can be tied to the server at one time. The order in which they are
specified dictates their execution order. Each login event handler has the ability to fail the login at any
time. A very common use for a login event handler is to look up a username and password in the
database before letting the user login to the server.
A logout event handler is used to execute code when the user logs out or disconnects from the server.
Unlike the login event handler, these do not work in a chain. Each one is fired in the order specified
but with no ties to their peer handlers. A common use for a logout event handler is to track the time
the user spent logged in by updating a database with the exit time.
5.1.3.3 User Variable Event Handler
A user variable event handler is used to listen for changes to user variables. It has the ability to
perform an action when a user variable is updated, deleted, or created. A good use for this type of
handler is to persist the variable to a database table so when a user next logs in, a login event handler
can automatically create the user variables for the user.
5.1.3.4 Buddy List Event Handler
A buddy list event handler is used to execute custom logic when a user adds, removes, or updates a
buddy on their buddy list. Like user variable event handlers, these are most commonly used to store
the data to the database. TBI
5.1.3.5 Private Message Event Handler
A private message event handler is used to listen for private messages sent between users and is
most often used for message logging or custom filtering. TBI
5.1.3.6 Extension Lifecycle Event Handler
An extension life cycle event handler is a special case event handler that is tied to a given extension,
not to the server itself. It listens for both the extension start up and shut down notifications. It is
generally used to initially load configuration data for the extension and provide that data to other
components in the extension. TBI
5.1.3.7 Audio/Video Event Handler
An audio/video event handler is another multi-purpose event handler. It is used to approve someone
attempting to publish or subscribe to a video stream much like a login event handler. It also serves as
a notification that a stream has stopped playing or that a user is no longer subscribing. TBI
Everything for an extension goes in a single folder. It's recommended that the extension name for this
folder is used, but it isn’t necessary as the Extension.xml file (described below) contains the extension
name the server will use. Technically the Extension.xml file is the only thing required to create an
extension, but wouldn’t be a very useful extension by itself.
The config folder is optional and is used to contain any configuration files specific to your extension.
The contents of the configuration folder will be added to the classloader for this extension. A good use
for the config folder is the applicationContext.xml file used for Spring or HBM files used for Hibernate.
The lib folder is optional and contains any libraries you need for your extension. In practice, these will
be jars and other dependencies. They will all be added to this extension's classloader instance.
The scripts folder is optional and contains all the script files needed by the extension. These files can
be in any language the server supports.
The classes folder is optional and is the equivalent to the scripts folder but for Java classes. Any
compiled classes will go in this folder as it will be added directly to the classloader.
5.2.1 Extension.xml
This file defines the contents of the extension and how it should be loaded by the server. The file is
broken down into a series of sections that define each component of the extension. The layout looks
like this:
<Extension>
<ManagedObjects>
<ManagedObject>…</ManagedObject>
</ManagedObjects>
<EventHandlers>
<LoginHandlers>
<LoginHandler>…</LoginHandler>
</LoginHandlers>
<LogoutHandlers>
<LogoutHandler>…</LogoutHandler>
</LogoutHandlers>
</EventHandlers>
<Plugins>
<Plugin>…</Plugin>
</Plugins>
</Extension>
Each section supports multiple entries. For example, many plug-ins could exist inside the Plugins
node as long as each is enclosed in its own Plugin node. The actual data definition of the extension
component is the same for all components and would look like this for a Java plug-in (if it had all
options enabled):
<Plugin>
<Handle>ExampleJavaPlugin</Handle>
<Type>Java</Type>
<Path>com.electrotank.electroserver4.testextension.SpringTest</Path>
<Synchronized>true</Synchronized>
<Variables>
<Variable name="Variable1Name" type="string">variable 1 value</Variable>
<Variable name="Variable2Name" type="string">variable 2 value</Variable>
</Variables>
</Plugin>
As noted before, every component uses the same structure in the Extension.xml file. Here is an
example ActionScript login event handler without variables:
<LoginHandler>
<Handle>ExampleActionScriptEventHandler</Handle>
<Type>ActionScript</Type>
<Path>login/AsLoginHandler.as</Path>
<Synchronized>true</Synchronized>
</LoginHandler>
Each extension is loaded with its own classloader as part of the overall classloader hierarchy to ensure
separation between extensions and the server. On the surface, this may seem an unnecessary
complexity, but it provides the most flexibility and convenience for extension developers. For instance,
by using a separate hierarchy we are able to ensure that extensions don’t interfere with each other.
This allows the server to run multiple instances of the same extension in parallel or even different
versions of the same extension at the same time. This also ensures that if one extension uses a
different version of the same library there will be no conflict between them.
The server loads all extensions together at start up but in no specific order. Any initialization process
that throws an error will prevent the server from starting the external listeners. This is to ensure that a
secure system isn’t brought online in an insecure manner accidentally. All start up errors will be in the
log files as well as in the web-based administrator.
In practice, this is a very valuable attribute. For instance, let’s assume a multiplayer game uses a
database to authenticate players. A login event handler uses a managed object factory to get access
to the database connection. The managed object factory uses its initialization method to create the
connection pool initially. On start up, a connection string is incorrect and the factory can’t connect to
the database. Rather than starting the server and possibly letting users log in without being
authenticated or logging errors every time the login event handler runs, the server simply flags the
extension as an error and ensures the external listeners don't start.
The server loads each extension sequentially in an undetermined order. Each extension runs through
the following process:
1. The extension life cycle event handler is constructed and initializes.
2. Managed object factories are constructed and initialized in the order they are defined.
3. Server-level plug-ins are constructed and initialized in the order they are defined.
4. Login event handlers are constructed and initialized in the order they are defined.
5. Logout event handlers are constructed and initialized in the order they are defined.
6. Private message events are constructed and initialized in the order they are defined.
7. User variable event handlers are constructed and initialized in the order they are defined.
8. Audio/video event handlers are constructed and initialized in the order they are defined.
Only when all extensions have started successfully does the server begin opening external listeners
and allow users to connect. As stated before, any exceptions while initializing will prevent listeners
from coming online and will be displayed in the logs and as start up errors in the web-based
administrator.
The extension shut down process works in exact reverse of the start-up process with the exception
that while errors are logged, they do not stop the process from continuing. The only two things that
can cause an extension to shut down are the server getting shut down (registry or stand-alone) or the
extension reloading which is described in the following section.
Extensions support the ability to dynamically reload if any changes are made to the contents of the
extension directory. Reloading an extension is a multi-step process that warrants a more detailed
description.
1. The server scans the extension directory looking for changes to existing extensions or newly
added extensions.
2. If a change is found, the server rescans the extension on short intervals waiting for changes to
settle out. This is to prevent an extension from being deployed while it is still being copied.
3. The extension is copied into the server’s temporary directory. If the extension is zipped up
currently, it is extracted during the copy.
4. If the extension is a duplicate of an existing extension, the existing extension is shut down via the
process described previously. To ensure the integrity of the system and prevent data mismatch
problems with the new extension, some users must be disconnected, according to the following
rules:
· Any user that has gone through a login event handler associated with this extension is
disconnected. This is to ensure that they will be forced to login through the newly deployed
extension.
· Any user that has had an associated extension-bound user-server-variable via the extension will
be disconnected. This is necessary because these users could have had an object associated
with them that may not be compatible with the new extension code base.
· Any user that is in a room and has a room-level plug-in from the extension will be kicked from
the room and the room will be destroyed. This is to ensure the room can be re-created with the
new code.
4. The new extension is started up using the procedure described above.
implementor of the ElectroServerApi by calling the getApi() method on the component. The api will be
available to the component by the time the lifecycle "init" method is invoked.
6 Advanced Topics
6.1 Understanding the EsObject
There are many components that make up a multiplayer application, including clients, server
extensions, and ElectroServer itself. Clients can be created as Flash applications, Java, BREW for
cell phones, or any number other platforms. Server extensions are written in Java or ActionScript. All
of these different parts of the overall multiplayer application need to communicate seamlessly for the
system to work. To this end, we created EsObject, designed to facilitate the exchange of data
between all layers of a multiplayer application.
EsObject is an object that supports a large number of data types. It allows the server and client, or
clients and other clients, to exchange simple or complex object structures that retain data types. In
addition, EsObjects are used in many places when dealing with extensions and values for room
variables, user variables, and user server variables.
One of the most attractive benefits of an EsObject is that it allows for data to be sent across languages
cleanly and easily. A plugin written in ActionScript can create an EsObject and send it to a Java client
and both sides will treat it consistently. There is no need to perform any messy conversions. For
example: A Flash client can create an EsObject, populate it with strings, numbers and arrays of
information, and then just send it to a server plugin. The plugin receives this EsObject and can access
all of that information.
· Public and private messages contain an optional EsObject property. This allows for custom data to
be attached to a chat message. For instance, which sound to play when the chat message arrives or
where to show the message on the screen.
· To log into the server, a client sends a LoginRequest. This request contains an optional EsObject
property. In general, this EsObject property would be captured and used by a custom Login Event
Handler installed on ElectroServer and written for custom login behavior.
· Plugin-to-plugin and client-to-plugin communication requires an EsObject to carry information.
6.1.1.2 EsObjects Used as Property Values
· User variables allow the storage of information on the server associated with that user in a
name/value pair format. The name is a string and the value is an EsObject. As a user travels from
room to room, other users see these user variables. See User Variables for more information.
· Room variables are a simple way to create information in a room that may stay there after the player
that created it leaves. Room variables are useful in games, and can be used for things like a white
board or room welcome message, etc. The value of a room variable is the EsObject. See Room
Variables for more information.
· Double, DoubleArray
· Float, FloatArray
· Short, ShortArray
· Long, LongArray
· Number, NumberArray
· Byte, ByteArray
· Char, CharArray
· EsObject, EsObjectArray
Note: A multiplayer game (with or without the Game Manager) usually happens inside of a room. A
room is a very convenient collection of users that allows the users to interact and so is ideal for nearly
all multiplayer games. The Game Manager manages games, and so it manages rooms that happen to
have extra properties associated with them. But at the heart of it a game is nothing more than a room.
Game types are registered by an extension. Typically this is done by a server-level plugin at server
startup time. See the server API documentation for exact information.
The game can modify its own game details at any time. The game details are returned in the list of
games whenever a list of games is loaded. A game of Texas Hold em poker might have game details
that specify the pot limit, number of seats available, and number of people currently playing. These
properties are seen by anyone inspecting the game list are completely custom per game.
A list of games that match the search criteria is returned (see FindGamesResponse). Each game in
the list is represented on the client by a ServerGame class. For each game the following information
is available:
• Game ID
• If the game is password protected
• If the game is locked
• Game details.
QuickJoinRequest
This is the easiest way for a user to get into a game. The client provides search criteria to limit the
potential list of games that they can join. If there is an open game that meets the search criteria
specified by the client, then the client is joined to that game. If there is no open game then a new game
is created and the client is joined to that game. With quick join a client is guaranteed to get into a game
(existing or new) as long as the game type specified has been registered.
To perform a quick join, a QuickJoinRequest object is created and populated with information. Some
of the information is used for find a game to join and some of it is used if no game is found and a new
one needs to be created.
· Game Type (string) – The type of game the client wants to join.
· Game Details (EsObject) – This is an optional property. If it exists and no game is found, then this
EsObject is used as the new game’s game details.
· Search Criteria (SearchCriteria) – This is an optional property. When the server searches for an
open game for the user to join it uses the provided SearchCriteria to limit the results.
· Zone Name (string) – This is used if no game to join is found and a new one is being created. The
new game will be created in the specified zone.
· Password (string) – This is an optional parameter. If specified it will be used against games that the
server finds that the user can join. If a new game is created then this password is used in that game.
CreateGameRequest
This request is used to create a new game. First a CreateGameRequest object is created and then it
is populated with the following information.
· Game Type (string) – The type of game that the client wants to create.
· Game Details(EsObject) – The game details object that is accessible by the game and seen
externally in the game list.
· Zone Name (string) – The name of the zone in which to create the game.
· Password (string) – This is an optional parameter. It should be specified if the client wants to create
a password protected game.
JoinGameRequest
This request is used by clients that want to join a specific game. When a game list is loaded the game
id for each game is available (so that is how a client would know a game id). To join a specific game a
JoinGameRequest is created and populated with the following information.
· Game Type (string) – The type of game that the client is joining.
· Game Id (number) – The id of the game as found in a list of games loaded using the
FindGamesRequest.
· Password (string) – This is an optional parameter. If the game specified is password protected then
the password field needs to be specified.
CreateOrJoinGameResponse
This response is always received after trying to create or join a game. It contains the success status
information. If the join was successful then it contains information about the game. If unsuccessful
then it contains an error.
· Successful (Boolean) – True if the client joined a game, false if not.
· Zone Id (integer) – The id of the zone that contains the game.
· Room Id (integer) – The id of the room that is the game.
· Game Details (EsObject) – The EsObject that is used to store the game’s details.
· Error (EsError) – If the successful property is false then no game was joined. This error tells you
why. See the full list of client errors for the most up-to-date information. But the following three errors
are at least some of what you can expect from an unsuccessful join: GameDoesntExist,
FailedToJoinGameRoom, GameIsLocked.
A plugin can get and modify its own game details EsObject.
Plugins have a userEnter event that is fired when a player is joining the room. Plugins have the ability
to stop this player from joining. Even if the game manager decides to put a player in the game, the
game can still reject the player. The ability of the userEnter event handler to reject a user from joining
a room is always there in a plugin – it is not a game manager feature, it is a plugin feature.
A login event handler extension is also required. When a user logs into the server, the extension will
retrieve their buddy list from the database and then add each buddy to that user for this session. This
technique gives the developer the ability to do a lot with buddies without being limited to a specific
database.
By default, published streams that are set to record save to the [installation directory] \server\video
directory. The file name is that of the stream.
To stream audio and video using ElectroServer the client must already be logged into ElectroServer.
Then an RTMP connection can be established via a new NetConnection class. The ActionScript API
handles creating this NetConnection class instance for you.
Once a NetConnection is established with ElectroServer the client has access to it. The client can use
the NetConnection to create NetStreams for publishing or subscribing to audio/video streams. You can
use the Flash documentation for all of the details on how to use NetConnection and NetStream.
-Xmx<amount>M
Simply replace the <amount> with the number of megabytes you want to make available.
ElectroServer will use this as the maximum available and will not exceed it.
The following sections cover how to adjust memory on different operating systems and environments.
8.1.1 Windows
8.1.1.1 Executable
If you are running the server as a stand-alone instance, the easiest way to set the command-line
parameter is to create a "batch" file. This is a file that Windows can use to run programs with settings.
7. Replace <type> with the name of the executable you use for the server. It might be ElectroServer,
RegistryServer, or GatewayServer depending on which you installed.
8. Replace <amount> with the amount of memory you want to use.
9. That's it! Now when you want to support the increased memory you just need to run "Start.bat"
when you want to start the server.
Here's a specific example, asking for 1024 megabytes and using the standalone server:
ElectroServer -J-Xmx1024M
pause
8.1.1.2 Service
If you are running the server as a service, then you need to update the service start parameters.
6. Press "OK". Next time you restart the server service or the server itself, it will use the increased
memory settings.
8.1.2 Unix
Adjusting the server to support more memory while running on Unix involves creating a very simple
shell script.
INSTALL4J_ADD_VM_PARAMS="-Xmx<amount>M"
7. On the next line, enter the command you normally use to start ElectroServer.
8. Press "escape".
9. Type in ":wq" (as always, ignore the quotes) and press enter.
10.You should be back and the command-prompt again. Run this command to allow others to execute
the file:
chmod 755 Start.sh
11.That's it! Now when you want to support more memory you just need to execute "./Start.sh" from
this folder to start the server.
Here's a specific example of a Start.sh file that sets the amount of RAM at 1024 megabytes and runs
the standalone server in a way that continues to execute even after the command window closes:
>nohup.out
INSTALL4J_ADD_VM_PARAMS="-Xmx1024M"
nohup ./ElectroServer &
9 Clients
9.1 ActionScript
ElectroServer 4 Flash ActionScript API is the integration point between the developer and
ElectroServer. Developers use the API to:
· Create requests to send to the server
· Capture responses and events sent from the server
· Manage users, rooms, and connections
This section covers the general structure and concepts behind the ElectroServer 4 ActionScript API. It
also discusses some differences between the ActionScript 2 and ActionScript 3 APIs, and finishes with
a list of commonly used classes and methods. For additional help, check out the tutorials section of
the ElectroServer website.
Note: Electrotank does not maintain an ActionScript 1 API for use with ElectroServer 4. If you want to
use ActionScript 1 with ElectroServer 4 you can, but you will need to write it yourself.
Both ActionScript 2 and ActionScript 3 APIs are available. These APIs are nearly identical. To use the
API in your application, you need to download it and add it to your application’s classpath. These APIs
are used to create content for the following Flash players and later: Flash 6, Flash 7, Flash 8, Flash 9,
Flash Lite 2.1, Flash Lite 3.
There are three important things to know about the ActionScript API, described in detail below.
Note: It is strongly recommended that Flash Develop or other ActionScript development tool that
supports Intellisense be used when developing ElectroServer applications. Intellisense (intelligent
code hinting) is invaluable when working with any rich API such as the ElectroServer 4 ActionScript
APIs. If you choose to code on frames or using the Flash IDE then you may find yourself needing to
look up information constantly. You can find Flash Develop at http://www.flashdevelop.org
9.1.1.1 The ElectroServer Class
The most important class in the API is the ElectroServer class which provides useful methods that
allows developers to:
· Create one or more socket connections to ElectroServer
· Send requests
· Create an RTMP connection for audio/video streams
· Create a binary connection for transfer of files such as images
· Access the internally managed data such as rooms, zones, users, buddies, and connections
import com.electrotank.electroserver4.ElectroServer;
var es:ElectroServer = new ElectroServer();
es.createConnection("127.0.0.1",9875); //ip, port
Figure 2: How to use the API to get the zone list, find a room in the zone, and trace the user names of users in
that room.
Nearly every time the Flash client sends something to the server, it is a request such as a
LoginRequest with a specific user name, or a JoinRoomRequest to join a room. Some requests will
generate a response from the server. For example: A LoginRequest will always cause a
LoginResponse. A response is nearly always sent from the server to the client (on rare occasion one
is sent from the client to the server). Things that happen on the server that the user needs to know
about are called events. User list updates, chat messages, and room list updates are examples of
events. Events are always sent from the server to the client.
var loginRequest:LoginRequest = new LoginRequest();
loginRequest.setUserName("coolio");
es.send(loginRequest);
Figure 3: LoginRequest object is created and then sent to ElectroServer using the ElectroServer
class.
9.1.1.3 Event Handling
The API captures client-bound server responses and events. The developer must use event listeners
to tie their own code to these events. The MessageType class contains every request, response, and
event the ElectroServer API uses. Every request, response, and event has its own class. This makes
for a larger but cleaner and less ambiguous API.
import com.electrotank.electroserver4.ElectroServer;
import com.electrotank.electroserver4.message.MessageType;
import com.electrotank.electroserver4.message.event.ConnectionEvent;
var es:ElectroServer = new ElectroServer();
es.createConnection("127.0.0.1",9875);
es.addEventListener(MessageType.ConnectionEvent, "onConnectionEvent", this);
function onConnectionEvent(e:ConnectionEvent):Void {
if (e.getAccepted()) {
//login
} else {
//tell the user login failed
}
}
Figure 4: Importing the ElectroServer class, the MessageType class, and the ConnectionEvent class.
A new instance of ElectroServer class is created and used to create a server connection. An event
listener is used to capture the ConnectionEvent.
Here are the places to look out for differences in the APIs:
· The ActionScript 2 API does not support binary protocol.
· The ActionScript 2 API EsObject supports get/set Integer, but uses Number.
send(request): When sending something to ElectroServer you must first create a request object
(such as LoginRequest), populate it with custom information if needed, and then use the send method
to send to ElectroServer.
9.2 Errors
The word error has a wide meaning here. When working with ElectroServer a client can perform
actions that indicate the client did something inappropriate (such as using vulgarity in a public
message) or that the server could not do what was asked of it (such as joining a room that doesn’t
exist).
Most errors are received by the client as a GenericErrorEvent. The specific error that occurred is
contained within the event details. For instance, if the user reaches the idle time out (they have been
inactive for too long) then they receive a GenericErrorEvent that contains a more specific
IdleTimeReached error.
If a user sent a request that requires a response, and that request caused an error, then the error is
contained within the response object. For instance, if a user sends a LoginRequest to the server that
contains a user name that is already in use, then the LoginResponse object contains a
UserNameExists error.
Error List
· UserNameExists – The user name used during login already exists.
· UserAlreadyLoggedIn – The user trying to login is already logged in.
· InvalidMessageNumber – The API sent a message to the server with an invalid message number.
· InboundMessageFailedValidation – The API sent a message to the server that did not pass
validation.