Introducing ElectroServer


As you can see, a socket server is a simple yet powerful communication tool. The specific implementations of a socket server may vary, but the basic idea is the same. There are several major socket servers available for Flash and quite a few minor ones. Here we'll introduce you to the one we know best, and which, of course, is best suited for the online gaming environment: ElectroServer. ElectroServer is a high-performance socket server designed by your friends at Electrotank (www.electrotank.com) with multiplayer Flash games in mind. Throughout this book, the multiplayer games have all used ElectroServer and its various features. Over the next few pages, we will discuss those features and how you can install, use, and administer ElectroServer for your own use.

graphics/exclamate_icon.gif

If you're planning to run the server, make sure to read "Properties File" in the "Configuring ElectroServer" section below.

graphics/hand_icon.gif

On the CD we have included a full version of ElectroServer and a demo license key. The demo license key is limited to five concurrent connections but will work on any IP address. This means that up to five people can be connected to the server at once. ElectroServer running in demo mode must be able to connect to the Internet every time it is started, or it will shut itself down. For the most recent information on ElectroServer, or if you are interested in a copy that accepts more than five concurrent connections, visit www.electrotank.com/ElectroServer.

Features

ElectroServer has several unique abilities that other socket servers don't support, and that allow for some sophisticated game functionality. We will start with the basic features and work toward the more advanced ones. Many features are configurable via a properties file (which we'll discuss in "Configuring ElectroServer" below).

Rooms. ElectroServer supports a room model for all chatting and games. This means that when you connect to the server, you are not automatically in a room, and you must join one to do anything.

Rooms can be either visible or hidden (in which case they don't show up on the room list). The ElectroServerAS object used in this book (and discussed in further detail in Appendix C) takes care of this for you. Making a game room invisible keeps people from attempting to join it.

When the number of users in a room changes, all rooms set to receive updates will be notified of the new room size. This is useful for getting a count of users in any given room. But rooms can also be configured to ignore these updates for performance reasons, and many people prefer that configuration.

Room list. All clients (users) receive an accurate list of all visible rooms on the server. This list contains the quantity of users in all rooms as well. It does not contain rooms that have been marked invisible.

User list. Within each room is a list of users for that room. This list is updated every time someone enters or leaves the room, so it is always up-to-date.

Private messages. ElectroServer supports the ability for users to send private messages to any specific player on the server.

Administrators. ElectroServer supports the concept of administrators. Administrators are users who have access to the kick and ban functionality (discussed below). To create or remove an administrator account, you use the built-in administrator console application (explained later).

Kick user. If a user is acting up (and believe me, this happens a lot), then you can kick the user from the server. This does not work in the same way as a kick in IRC (which only removes you from a room). In ElectroServer, the kick command disconnects a user totally from the server and gives him a message about why he was booted. This command is only available to users who have administrator-level status.

Ban user. If a user is being particularly bad, you can ban her from the server. Ban is based on the user's IP address, so it is not foolproof. But it is permanent if you ban her and restart the server, she is still banned from the system. An administration tool is provided to remove users from the ban list. The ability to ban is only available to users who have administrator-level status.

Logging. ElectroServer provides extensive logging functionality to ensure smooth operation. When the server starts, it initializes all necessary components and logs that information to the screen. Once the components are started and the server is listening for users, it starts logging instead to whatever location is specified in the properties file. If requested, the server will roll log files rename the old file and start a new one with the original name at startup. The server supports configurable levels of logging, allowing you to determine how much or how little information you want to capture. All error, kick, and ban messages are logged no matter what.

Language filtering. ElectroServer supports the ability to determine if a player is using words that are prohibited on the site. The prohibited words are listed in a text file specified in the properties file. This feature can be enabled or disabled and has many configurable options, including the ability to kick the offenders from the server.

System messages. A system message is one transmitted to all users in all rooms, regardless of their status. It can be used to inform users of events about to occur, such as a server restart or a celebrity chat. Only administrator-level users can send out system messages.

Room variables. graphics/hand_icon.gif A room variable is defined at the room level by a user. These variables have various configurable behaviors. For instance, a room variable can be configured to remove itself when the user who created it leaves the room. A room variable can be locked to protect it from being overwritten, or it can be persistent and maintained even when the user who created it leaves the room. Room variables are automatically sent to all users when they are created, modified, or deleted. A user gets all the room variables in a room when he joins the room. Room variables are one of the features that make ElectroServer especially well suited for games.

Object serialization. This powerful ElectroServer feature actually stems from its client-side object. The ElectroServerAS object supports the ability to take most ActionScript objects not bound to physical resources (such as movie clips and sound clips) and send them to the room the user is in, or even use them as room variables. This makes it quick and easy to send complicated data structures to anyone you wish.

Detect updates. ElectroServer supports the ability to automatically check for updates to its code over the Internet. When the server first starts, it makes an HTTP connection to www.electrotank.com and checks the available versions. It determines if the version online is newer than your current version and notifies you.

Administration. ElectroServer supports several console-based administration applications to ease administering the server. You can manage the administrator accounts, as well as the banned-user lists, from simple console applications.

Installing ElectroServer

While this is a production-quality server, you can very easily run it on your local workstation. In fact, that is the recommended way to develop multiuser applications.

There are several ways to install ElectroServer. As ElectroServer is written completely in Java, it will run on any platform that supports the 1.3.1 Java Virtual Machine. Sun Microsystems currently has downloads for Windows, Solaris, and Linux; and many other platforms support Java as well, such as Mac OS X and HPUX.

The first thing you need to do, regardless of platform, is install the Java Virtual Machine. For Windows, Solaris, or Linux you can find it at Java.Sun.com (http://java.sun.com). For Mac OS X, you can find it at Mac OS X Java Runtime Environment (http://developer.apple.com/java).

Follow the directions listed with the download and install the Java environment. When you are completely finished, you should be able to type java from a command prompt and get a response that looks something like this:

 C:\WINDOWS\Desktop>java  Usage: java [-options] class [args...]           (to execute a class)    or  java -jar [-options] jarfile [args...]            (to execute a jar file) 

This is how it looks for the 1.4 JVM, so yours might look a little different. At this point, your computer should be able to run Java applications, and you should be able to proceed with the actual installation of ElectroServer, which should be very simple.

Windows Installation

Run the Windows installer (setup.exe) for ElectroServer from the CD included with this book. You'll find it in the Demos\ElectroServer\Windows folder. Run this application as you would any other, and follow the onscreen prompts to finish installing ElectroServer. This installation will create a Start-menu group as well as a script you can use to start and stop the server as needed. The setup application also creates an uninstaller.

Unix Installation

Locate the Demos\ElectroServer\Unix folder on the CD. Copy the files in that directory to the location from which you want the server to run. Usually it's something like /usr/local/ElectroServer, but that is completely at your discretion. Then execute the Setup.sh script. It will extract the contents of the .tar file into your current directory. The server should now be installed correctly.

Other Platform Installation

Locate the Demos\ElectroServer\Generic folder on the CD. Take the .zip file in that folder and manually extract it to wherever you want the server to execute.

The difference you will see between this installation and the other installation methods is that this one won't create easy-to-use start and stop scripts for you.

Configuring ElectroServer

Now that you have the server and Java installed, you need to configure it to reflect your desired environment, startup options, and features. Configuring ElectroServer is quite simple; everything you need to manage or change can be done through either an easy-to-use console application or the text-based properties file.

Properties File

Most of the ElectroServer configuration occurs through the ElectroServer.properties file that is created in the installation directory. You can open this file in any text editor, such as Notepad or VI. The various configuration options for the ElectroServer.properties file are documented right in the file, so we will not cover that information here. Any changes to the properties file require you to restart the server.

graphics/hand_icon.gif

There are two configurations that are crucial to starting the server. The first is

 General.LicenseFileLocation  

This option points to the ElectroServer license file in the installation directory, without which the server cannot start. By default, it points to the demo license file, which lets you run the ElectroServer on any IP address and port, but with a maximum of five connections at once. This license also requires the server to be able to connect to the Internet, or it will not start. If you have any settings in the properties file that don't match your license file, the server will inform you of that, and shut down.

The second crucial configuration is

 ChatServer.IP  

This setting is used for the chat server's IP address. By default, it is set to 127.0.0.1. This is the loopback IP for your machine, as we discussed previously. You will have to change this if you want other people on the Internet to connect to the server.

Administrator Accounts

If you wish to have administrators for your chat server, you have to set the ChatServer.AdministrationEnabled setting in the properties file to true. Once this is done, you will need to run the ElectroServer administration tool to add administrators. Here's how you can run the tool in various platforms.

Windows Either choose the Start Administrator option from the Start menu or go to ElectroServer's installation folder and run the file StartAdministrator.bat.

Unix From ElectroServer's installation folder, run StartAdministrator.sh.

Other platforms From ElectroServer's installation folder, run

 java -cp ElectroServerV2.jar com.electrotank.electroserver   .admin.ElectroAdmin 

Please note that no matter how this looks onscreen, it's one command line.

Once in the tool, choose the Manage Administrator Accounts option and follow the onscreen prompts.

Language Filter

The Language filter manages a customizable list of any words you want blocked on your chat server. You simply specify the location of the bad-word list in the ElectroServer.properties file. This list is a plain-text file in this format:

 Badword1  Badword2 ... Badword10 

You can change this file at any time, but you need to restart the server in order to see those changes.

Banned IPs

If some IP addresses have been banned on the server and you want to remove them from the restricted list, you will need to run the ElectroServer administration tool. You can run the tool in the same way you did for administering admin accounts. Once in the tool, choose the Manage Banned IP Addresses option, then follow the onscreen prompts.

Running ElectroServer

Running ElectroServer is similar to running the Administrator very simple. As you can imagine, the server must be started before you can jump into testing, playing, or chatting.

Starting the Server

Windows Choose the Start ElectroServer option from the Start menu, or go to the ElectroServer installation folder and run StartElectroServer.bat.

Unix Run StartElectroServer.sh from the ElectroServer installation folder.

Other platforms Run

 java -cp ElectroServerV2.jar com.electrotank.electroserver   .ElectroServer ElectroServer.properties 

from the ElectroServer installation folder.

Stopping the Server

Windows Choose the Stop ElectroServer option from the Start menu, or go to the ElectroServer installation folder and run StopElectroServer.bat.

Unix Run StopElectroServer.sh from the ElectroServer installation folder.

Other platforms Run

 java -cp ElectroServerV2.jar com.electrotank.electroserver  .StopES ElectroServer.properties 

from the ElectroServer installation folder.

ElectroServer has been around from almost the beginning of Flash 5 and has seen a lot of use for many different applications. It has been used by multiple companies on many platforms with great success. With a little effort, you should have no trouble adapting it for your needs.



Macromedia Flash MX Game Design Demystified(c) The Official Guide to Creating Games with Flash
Macromedia Flash MX Game Design Demystified: The Official Guide to Creating Games with Flash -- First 1st Printing -- CD Included
ISBN: B003HP4RW2
EAN: N/A
Year: 2005
Pages: 163
Authors: Jobe Makar

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net