Flash Multiplayer Virtual Worlds - Makzan Makzan (Mak Seng Hin) - E-Book

Flash Multiplayer Virtual Worlds E-Book

Makzan Makzan (Mak Seng Hin)

0,0
39,59 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Flash virtual worlds are some of the most exciting—and profitable—online business being built today. Using Flash, developers can build interactive environments where users can interact with the virtual world and one another, compete, and have fun. Creating a playful environment on an electronic network presents unique challenges as you combine a fun, upbeat frontend with some serious and complex server logic.

This handy book assists you in building amazing virtual worlds in no time by implementing ActionScripts in a Flash IDE. With this book in hand, you will build virtual worlds that have avatars walking around and interacting with non playing characters, completing challenging quests, and allowing users to link with real-world friends.

The fun begins with first exploring existing virtual world games such as Club Penguin, Mole, Dofus, and World of Warcraft. We will then design our virtual environment. Then we will create avatars and move the avatars in the virtual world. We will add some triggers to add amusement and life to the virtual world. We will allow the avatars to interact with other players and create a buddy list for each user. Then we will integrate buildings and other environment to the virtual world. We will also let the players interact with non-player characters to complete some tasks. Finally, we move on to add interesting quests to the virtual world, which need to be accomplished by the player to gear up to the next level of the game.

This example-rich, hands-on guide sequentially develops a multiplayer virtual world—the platform, the environment, quests, avatars, non-playing characters, and interaction between them.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB

Seitenzahl: 407

Veröffentlichungsjahr: 2010

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Flash Multiplayer Virtual Worlds
Credits
About the Author
About the Reviewers
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Errata
Piracy
Questions
1. Developing Flash Virtual World
What is a virtual world?
Using virtual world for business
Using virtual world for education
Using virtual world for game
Background
Benefit of using Flash to build virtual world
Connecting players in a virtual world
A brief introduction to transport protocols
Peer-to-peer
Client-server network
Polling
Socket-based connection
Socket server
Available socket servers for Flash
SmartFoxServer
ElectroServer
Flash Media Interactive Server
Red5
Writing your own socket server
Choosing the right server
Application architecture of a virtual world
The whole picture of virtual worlds
Common features in virtual world
Avatar
World to explore
Home
Items
Quests
Non-player characters
Social features
Casual game design versus MMOG
Existing virtual world games
Club Penguin
Mole
Dofus
World of Warcraft
Summary
2. Installing the Servers
Comparing SmartFoxServer Lite, Basic, and Pro
SmartFoxServer Lite
SmartFoxServer Basic
SmartFoxServer Pro
Modifying the behavior of server
JSON/Raw data protocol
Accessing the database directly
Comparing different package options
Developing and deploying virtual world environment
Adjusting server setting for the deployment environment
Hosting SmartFoxServer, web server, and database in one server
Hosting SmartFoxServer in dedicated standalone server
Benefiting from setting up SmartFoxServer, web server, and database in different machines
Setting up the development environment
Installing Java Development Kit
Installing JDK On Windows
Installing JDK on Mac OSX
Installing JDK on Linux
Installing for General Linux
Installing for Ubuntu Linux
Downloading SmartFoxServer Pro
Installing SmartFoxServer Pro
Installing on Windows
Installing on Mac OSX
Installing on Linux
Running the SmartFoxServer
Starting SmartFoxServer on Windows
Starting SmartFoxServer on Mac OS
Starting SmartFoxServer on Linux
Using embedded web server and database
Running the embedded web server
Running the embedded database server
Downloading third-party HTTP and database server package
Installing WAMP on Windows
Installing MAMP on Mac OSX
Installing LAMP on Linux
Connecting SmartFoxServer and MySQL server
Downloading JDBC Driver for MySQL
Setting up the JDBC driver
Configuring the server settings
Configuring MySQL server connection in SmartFoxServer
Restarting the server
Running examples
Loading a simple chat application
Setting up the administration panel
Logging in to administration panel
Locating the Flash Client API
Summary
3. Getting Familiar with SmartFoxServer
Configuring a basic SmartFoxServer
Overview of the configuration file structure
Configuring the server
Automatically binding all available IP addresses to server
Listening port for connections
Setting policy load data from machines in other domains
Setting timers for idle user logouts
Blocking bots connections
Setting administrator login and password
Limiting access of the administration panel to specific IP addresses
Displaying zone information before connecting to the server
Defining the information separator in raw protocol
Configuring the Zones and Rooms
Configuring a zone
Naming your zone
Assigning default names to users
Broadcasting the user count
Limiting the users that can connect to a zone
Limiting numbers of rooms in a zone
Limiting the number of rooms a user can create
Getting all room variables along with room list requests
Setting moderators for the zone
Creating rooms
Regular room
Game room
Limbo room
Properties of a room
Comparing the available properties of each room type
Introducing the events of rooms
Comparing the available events of each room type
Debugging in local machine
Downloading the latest debugger version of Flash player
Creating the mm.cfg file
Testing the debugger log
Locating the Flash log output file
Reading the Flash logfile
Open the flashlog.txt in web browser
Using a Firefox add-on to read the Flash logfile
Reading the log with FlashTracer
Reading the log with FlashBug
"Tail" the trace log file in terminal
Flash Security Sandbox
Configuring master socket policy server
Configuring SmartFoxServer to send socket policy
Loading policy file from Flash client
Enabling the network access for the Flash document
Keeping updates to Flash player security policy
Creating a Flash document to connect to the server
Logging into a zone
Creating a cooperative drawing whiteboard
Testing the cooperative whiteboard
Summary
4. Creating Map and Ground in Isometric View
Comparing different game views
Top-down perspective
Side-scrolling view
3D view
Isometric game view
Getting an isometric projection view
Isometric coordination
Making an isometric map
Creating the base tile of an isometric map
Creating a basic isometric tile map
Drawing seamless shore border
Texturing an isometric map
Texturing a big map
Converting between screen coordination and isometric map coordination
Building a map editor
Summary
5. Creating Avatars
Designing an avatar
Determining the direction numbers of avatars' views
Rendering avatars in Flash virtual world
Drawing an avatar using vector animation
Rendering avatars using bitmap sprite sheet
Rendering avatars using real-time 3D engine
Rendering avatars using 2D bone skeleton
Drawing an avatar in Flash
Drawing the idle and walking animation
Creating an avatar class
Logging in SmartFoxServer with avatar
Using user variables in virtual world
Adding name to the avatar
Customizing your avatar
Customizing different styles
Customizing the color
Adding customization to avatar class
Designing a customization panel
Making our customization panel
Integrating the customization into SmartFoxServer
Summary
6. Walking Around the World
Creating the world
Holding states of the player
Moving the avatar
Movement synchronization
Making avatar able to walk
Walking by keyboard
Introducing path finding
Implementing A* search
Understanding the heuristic function
Balancing between accuracy and speed
Walking by mouse click
Broadcasting where you walked
Scrolling the world
Saving the position for next time
Creating an avatar database table
Creating a new zone in config.xml
Programming our first server-side extension
Saving and loading last position
Summary
7. Creating Buildings and Environments in the Virtual World
Placing buildings on the map
Outputting building from 3D software
Loading the building map data
Ordering the buildings
Ordering the movie clips in Flash
Determining an object's location and view
Shaping the buildings
Rendering z-order for l-shaped buildings
Rendering z-order for rectangle buildings
Rendering z-order for square buildings
Creating a loop to sort the z-order
Designing a big virtual world
Dividing the big world
The pros and cons of the seamless world
Partitioning the world into rooms
Connecting rooms with portals
Adding sound to the virtual world
Mixing art-based background with tile-based map
Building map editor for buildings
Summary
8. Creating an Inventory System
Classifying items in the virtual world
Different types of items
Items for avatar
Weapon
Tools
Riding
Entertainment
Material item
Collecting items
Collecting items that appear in the open
Collecting items that are hidden
Getting items after archiving some quests
Buying items in virtual shop
Trading items with other players
Buying from real shop
Displaying items in different forms
Defining the data structure of inventory items
Setting the item ID
Implementing inventory in the SmartFoxServer
Coding the server-side extension
Implementing the item panel
Loading the item definition
Loading the items list from the server
Moving items
Implementing the item operation in RAM
Creating items
Exchanging items with other players
Introducing the economy in virtual world
Balancing the items virtual economy
Setting the price of the items
Preventing the inflation
Hosting special event
Adding fatigue to items
Limiting the total amount of high-level items
Preventing the virtual economy from affecting the real world
Trading with real money
Government policy on virtual items
The responsibility to maintain a good economy system
Summary
9. Communicating with Other Players
Communicating using several methods
Sending public messages
Sending private messages
Sending group messages
Communicating in real-time voice
Potential problems of using voice communication
Consumes a lot of server bandwidth
Message filtering problem
Number of users limitation
Logging and revisit problem
Chatting with public messages
Showing chat bubble
Scaling the chat bubble
Implementing the buddy list
Creating buddy list panel
Knowing others with profile panel
Dispatching custom event in ActionScript 3
Creating an advanced buddy list
Adding buddy mutually
Introducing the buddy variables
Offline buddy variables
Creating custom buddy list persistence class
Summarizing buddy list configuration setting
Sending private messages
Capturing private message in server-side with internal event
Sharing object data between players
Making the trading items system
Summary
10. Interacting with NPC
Running virtual world smoothly with NPCs
Classifying different roles of NPC
Placing NPC in virtual world
Putting our first NPC in the virtual world
Preventing the NPC from disconnecting
Resolving a potential problem of using provided NPC feature
Advanced SmartFoxServer extension technique
Controlling NPC movement
Controlling NPC to walk in predefined path
Directing NPC to walk using path finding algorithm
Talking with NPC
Communicating with NPC using text parsing
The advantages of text parsing conversation
The disadvantages of text parsing conversation
Menu-driven conversation
The advantages of the menu-driven conversation
The disadvantages of the menu-driven conversation system
Keyword-based conversation
Choosing the right conversation system
Designing the characteristic of the NPC
Trading with NPC
Buying items from NPC
Selling items to NPC
Summary
11. Designing Quests
Introducing quests
Triggering quests
Getting quests from NPC
Getting quests from reading documents
Getting quests from collecting items
Getting quests from the last quest
Setting up server environment for quests
Setting up database
Designing the quest panels
Displaying available quests
Getting available quests in server-side extension
Displaying the quests in different statuses
Displaying quests for the avatar
Running daemons for quests
Managing quest daemons
Creating our first quest — Tom's Question
Introducing achievement
Completing quests
Rewarding the players when finishing the quests
Rewarding gold
Rewarding items
Rewarding avatars advancement or experience
Extending the quests with mini games
Creating the duck shooting game
Implementing the duck shooting quest daemon
Making the quest system better
Avoiding linear quests
Indicating the availability of quests
Summary
12. Social Community
The benefit of using social network features in virtual world
The complicated data flow
Integrating Facebook platform
Setting up Flash Facebook API
Registering the virtual world in Facebook
Putting the virtual world as a Facebook application
Using FBML rendering
Using iFrame rendering inside Facebook
Authorizing a Facebook account
Getting the profile name and picture from Facebook
Getting friends list from Facebook
Update the Facebook status
Sending news feed to Facebook
Reading news feed into the virtual world
Capture a screenshot and share to a Facebook album
Integrating the Twitter platform
Publish latest virtual world news in Twitter
Choosing the right social network service
Summary
13. Deploying and Maintaining Flash Virtual World
Hosting the virtual world
Hosting that supports SmartFoxServer
Hosting SmartFoxServer in dedicated server
Hosting SmartFoxServer in cloud service
Comparing the hosting solution
Scaling up the virtual world
Earning money from the virtual world
Google AdSense
In-game advertisement
Monthly subscription
Point-based subscription
Selling virtual items and virtual currency
Operating the virtual world
Tracking the cost of maintaining a Flash virtual world
Paying the hosting fee
Licensing the Socket server
Hiring customer service
Losing players
Losing players at sign up process
Losing players at a certain level
Losing players after updates
Losing players due to the low quality
Product lining
Analyzing players actions on a virtual world
Tracking players actions with funnel analysis
Data mining
Gathering useful information
Logging the data
Rapid development with OpenSpace
Editing with advanced map editor
Raising the avatars from the flat platform
Creating custom tile events
Updating and patching the virtual world
Keeping an eye on the virtual world industry
Putting our virtual world in mobile
Small screen size
Low RAM
Relatively slow CPU
Limited network bandwidth
Benefit of porting virtual world into mobile
Extending the virtual world to other platforms
Apple iOS
.Net and Unity
Java and Android
Ajax
Summary
Index

Flash Multiplayer Virtual Worlds

Flash Multiplayer Virtual Worlds

Copyright © 2010 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, Packt Publishing, nor its dealers or distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: August 2010

Production Reference: 1100810

Published by Packt Publishing Ltd.

32 Lincoln Road

Olton

Birmingham, B27 6PA, UK

ISBN 978-1-849690-36-2

www.packtpub.com

Cover Image by Vinayak Chittar (<[email protected]>)

Credits

Author

Makzan

Reviewers

David Crebbin

Prashanth Hirematada

Sergey Suchok

Acquisition Editor

David Barnes

Development Editor

Reshma Sundareshan

Technical Editor

Rukhsana Khambatta

Copy Editor

Sanchari Mukherjee

Indexer

Monica Ajmera Mehta

Editorial Team Leader

Gagandeep Singh

Project Team Leader

Priya Mukherji

Project Coordinator

Ashwin Shetty

Proofreader

Lynda Sliwoski

Graphics Coordinator

Nilesh R. Mohite

Geetanjali Sawant

Production Coordinator

Adline Swetha Jesuthas

Cover Work

Adline Swetha Jesuthas

About the Author

Makzan is a game designer working in Macao and Hong Kong, China.

He started as a web designer and met Flash 4 in 2000. He won a bronze medal in WorldSkills for Web Designing and later became the expert of Macao in this competition.

He has interest in creating games and often explores different ways to implement his game ideas such as making Flash games on Wii, mobile games on iPhone, and social games on Facebook.

Since 2003, Makzan started making multiplayer Flash games with different server solutions. He tried most existing multiplayer game solutions until discovering SmartFoxServer.

I would like to thank the following groups of people for all their efforts. The book would not be possible without the help from the Editors, Reviewers, Proofreaders, and the Project Coordinators. I thank all the reviewers for providing very useful comments from which I have learnt a lot. I thank David, my Acquisition Editor, for inspiring me on the book's ideas. I thank Reshma, my Development Editor, for revising my chapters and helping me in writing them. I thank Ashwin, the Project Coordinator, for the great cooperation while delivering the chapters. I thank Rukhsana, the Technical Editor, for helping me on revising chapters. I thank Kelvin Fong for drawing the graphics of the code examples. I thank again all the people who have worked on this book. Thank you.

About the Reviewers

David Crebbin has spent most of his working life developing and architecting client-side applications, with the vast majority of his projects utilizing ActionScript. He's a firm believer in the technology and what it can offer, along with its amazingly creative developer community. He has used the Flash platform to build both small and large scale applications covering e-learning, gaming, and television.

Prashanth Hirematada is the founder of Gamantra, a game technology company focused on Network engine and server platform. Prior to founding Gamantra in 2006, he was a Chief Architect at Shanda Interactive Entertainment Ltd., where he was responsible for creating a common game development platform for all MMOG initiatives at Shanda. He joined Shanda in 2004 through Shanda's acquisition of Zona, Inc., a MMOG game technology company, headquartered in Santa Clara, U.S.A. At Zona, as a Technical Chief Architect, he was responsible for server-side architecture and implementation of MMOG framework. Prior to joining Zona in 2001, Prashanth worked in various Silicon Valley based technology start-up companies developing software at various levels for well over seven years.

His Master's thesis was a distributed implementation of the Message Passing Library (MPI) on a heterogeneous network of workstations including Solaris, HP-UX, OpenStep, and Windows-NT. He received his M.S. in Computer Science from California State University, Sacramento, California, in 1994 and his B.S. in Computer Science from Bangalore University, Bangalore, India in 1992. He can be contacted at <[email protected]>.

Sergey Suchok graduated in 2004 with honors from the Faculty of Cybernetics, Taras Shevchenko National University of Kyiv (Ukraine) and has since then been keen on Information Technology. He is currently working in the banking area and prepares to defend his thesis on the modeling of banking operations. Sergey is the co-author of more than 40 articles and has participated in more than 20 scientific and practical conferences devoted to the economic and mathematical modeling. He is a member of the "New Atlantis" Youth Public Organization (newatlantida.org.ua) and devotes his leisure time to environmental protection issues, the historical and patriotic development and popularization of a grateful attitude toward the Earth. He is also developing a social network for Kombucha's owners called Latusho, and he writes poetry and short stories and makes macramé.

I would like to express gratitude to the author for this opportunity to improve my knowledge of game development, as well as to Packt Publishing for providing such an interesting experience in the review process.

Preface

Back in the late 1970s, digital virtual world and multiuser adventure games, MUDs, made their debut. At the time Internet reached the masses and got popular in 1990s, Massively Multiplayer Online Games, MMOGs, became the new market that every game company was eager to get into. Players download or buy discs to install the online virtual world. The world gives players a virtual personality and they can play and interact with each other to finish tasks.

Being a multimedia and interaction platform, Adobe Flash introduced socket connection support to Flash player. The socket connection allows Flash player to connect persistently to a socket server and provide the opportunity for multiple user Flash applications. In other words, socket connection makes it possible to create a Flash online virtual world.

Compared to the traditional multiplayer online games, Flash online virtual worlds are browser-based and do not need any installation (except the Flash player plugin). They allow players to quickly play the virtual world game just like browsing a web page. The convenience fits the nature of Internet and thus can reach a larger variety of potential players.

Thanks to the quick evolution of socket networking service during these years, Flash online virtual worlds are becoming a trend. Every day users log into social networking sites and play with friends on their virtual farms or virtual towns.

With this book, we will have a step-by-step guide to create our own Flash virtual world from scratch. We will discuss several essential parts of creating a Flash virtual world and integrating it into social networking services. At last, we will have a look on how to deploy and operate our virtual world in production and earn money from it.

What this book covers

Chapter 1, Developing Flash Virtual World, discusses the benefit of developing a Flash virtual world. It also discusses different connection methods between Flash clients and compares different server solutions. You will also get introduced to the common features in a Flash virtual world such as avatar, home, items, quests, non-player characters, and others. You will also know about some existing virtual world games such as Club Penguin, Mole, Dofus, and World of Warcraft.

Chapter 2, Installing The Servers, develops and deploys a virtual world environment. You will also install the Java Development Kit and SmartFoxServer, connect it with MySQL server and configure the server settings. You will then load a simple chat application and set up and log in to the administration panel.

Chapter 3, Getting Familiar with SmartFoxServer, configures a Basic SmartFoxServer and discusses how to set up the Flash player to view the Flash trace log without the Flash IDE. You will also see how we can prevent the Flash loading data or connect sockets to other resources that are not in the same domain of the hosting server by using the Flash player's inbuilt security sandbox. You will also create a Flash document to connect the server and finally, create a whiteboard that every connected user can draw on and test it.

Chapter 4, Creating Map and Ground in Isometric View, compares different game views, create an isometric map, and a ground for the virtual worlds. You will then build a Map Editor, which will be used later for development.

Chapter 5, Creating Avatars, designs an avatar and draws the avatar in Flash. You will then customize your avatar with different styles and colors. You will also design and create a customization panel and finally, integrate it to the SmartFoxServer.

Chapter 6, Walking Around the World, covers the different methods to move the avatar in the virtual world. You will code your first server-side extension and create the connectivity between Flash client and the database.

Chapter 7, Creating Buildings and Environments in the Virtual World, teaches you how to place a building on the Map and order the buildings while displaying them. You will also create a map editor for the buildings.

Chapter 8, Creating an Inventory System, classifies items in the virtual world and also discusses about avatars collecting items. You will also learn about defining the data structure of an inventory item and implementing an inventory and an item panel.

Chapter 9, Communicating with Other Players, discusses the various methods for communicating in the virtual world which includes chatting with public messages. You will also learn how to implement a buddy list, add players to it, and finally send messages to these players. You will also see how we can share items between players.

Chapter 10, Interacting With NPC, shows how we can run a virtual world smoothly by introducing non-player characters. You will place your first NPC and control its movements. You will see the different communication methods available for the NPC and how to trade items with the NPC.

Chapter 11, Designing Quests, introduces quests and how they can be triggered in a virtual world. You will set up server environments for quests and design quest panels. You will also see how you can encourage players to participate in quests by placing rewards and improving the quests.

Chapter 12, Social Community, discusses the benefits of having a social networking feature in your virtual world. This chapter will show you how to integrate with the Facebook and the Twitter platforms.

Chapter 13, Deploying and Maintaining Flash Virtual World, shows how you can host the virtual world and operate the virtual world. You will also see some methods to earn money from virtual world. You will also learn to transfer your virtual world to mobile and other platforms such as Apple iOS and .NET and Unity, among others.

What you need for this book

The software that are required for this book are SmartFoxServerPro_1.6.6, Adobe Flash CS4, and MySQL 5.1.

Who this book is for

If you are a Flash or an ActionScript developer who wants to build powerful and immersive multiplayer games, this book is for you. This book assumes that you have some experience with ActionScript 3.0.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book — what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply drop an e-mail to <[email protected]>, and mention the book title in the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail <[email protected]>.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Tip

Downloading the example code for this book

You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our contents, mistakes do happen. If you find a mistake in one of our books — maybe a mistake in text or code — we would be grateful if you would report this to us. By doing so, you can save other readers from frustration, and help us to improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata added to any list of existing errata. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at <[email protected]> with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at <[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.

Chapter 1. Developing Flash Virtual World

Online game community has been popular for years. Recently many virtual worlds are Flash-based and can run directly in web browser. The latest Flash player 10 and ActionScript 3 gain a performance leap from older Flash player and ActionScript 2. The memory consumption is around 50 percent more and the script performance is around 10 times faster than ActionScript 2.

Thanks to the performance enhancement and the binary socket connectivity support of the latest ActionScript, building Flash virtual world is possible for even independent Flash developers.

In this chapter, we will discuss the benefit of developing Flash virtual world. We will also discuss different connection methods between Flash clients and compare different server solutions.

What is a virtual world?

A virtual world is a digital environment that is similar to real world. Many users can log in to the virtual world and walk around in a virtual city or interact with each other. They can interact with others in different ways such as collaborating, chatting, or playing together.

Let's see how virtual world is used in different areas.

Using virtual world for business

Virtual world connects users in real time so that they can socialize in this virtual environment. They can collaborate with others in an online meeting or virtual workspace. Users can even share their thoughts by Voice-over-IP chatting or whiteboarding.

MPK20 (http://research.sun.com/projects/mc/mpk20.html) is one of the virtual workspaces from Oracle, previously Sun. It facilitates several features to target business users. Users in MPK20 can join a briefing with a PDF presenting, join a group meeting or even drag in documents from a computer to share between users for discussion. The following screenshot shows the virtual workspace from MPK20:

Using virtual world for education

Students can play in a simulated reality environment in virtual world. In this environment, students are given some tasks to complete. They can collaborate with other students to complete the tasks assigned by teachers. The students may learn things by immersive learning when solving different missions inside the virtual world.

Using virtual world for game

People can play games with others in virtual world. They can play against other players in real-time battle or team up to play against the missions from the online game. They may also exchange items and establish relationships like in the real world.

The following screenshot is from an online game called Mini Fighter (http://global.netmarble.com/minifighter/). It is a virtual world where players can fight against a lot of players at the same time in a 2D horizontal environment.

Background

In the 70s, there was MUD. MUD stands for Multi-User Dungeon and it is a text-based virtual world that players connect to through Telnet. Players connect to the MUD and interact with others or the world by inputting commands. They get feedback and information from text description. Later in the 80s, some graphical virtual worlds based on MUD were released. They were actually MUD which changed the present method from text to graphic and from command input to GUI input.

Later, Ultima Online (http://www.uoherald.com/) and EverQuest (http://www.everquest.com/) brought multiplayer virtual worlds to a new level. World of Warcraft (http://www.worldofwarcraft.com) and Second Life (http://secondlife.com/) followed EverQuest and they all made the trend of online games and virtual worlds.

In recent years, Flash virtual world is becoming more popular. Many new virtual world communities released Flash-based instead of traditional installer-based. In the beginning, Flash virtual world is not mature due to the performance issue of Actionscript 1 and old Flash player. After the introduction of ActionScript 2 and ActionScript 3, the programming language has been enhanced and the performance of Flash player boosts to support better network connections and better graphics. This makes the spring of Flash virtual world.

Benefit of using Flash to build virtual world

Traditional installer-based games require users download an installer or they may even need to buy an installer disk in game shop in order to play the game. And the requirement of installing software means that users may not be able to play it wherever they want. For example, they may not have the privilege to install the software on a friend's computer or public computers.

A Flash player-based virtual world does not require downloading an installer. As long as the web browsers have the Flash player plugin that fulfills the required version, users can log in and play the whole game inside the web browser directly. Traditionally users go to the game website, download the game, install it, log in, and play it. Now with Flash player-based game, users go to the game website, log in, and play it. This simplifies the flow to start playing the game.

Moreover this will attract those first-time players. When someone is landing on the game website and finds the game quiet interesting, they are willing to give it a try. At this time, it will be much better if they can log in through the guest account and try the virtual world immediately instead of downloading a big installer and waiting half an hour before starting the game, as shown in the following screenshot (these are the screenshots of the welcome page of Club Penguin and MMOG):

Another benefit of using Flash is the seamless update of the client application. It is common that updates and patches ship to the existing users after releasing the virtual world. In traditional installer-based virtual worlds, users have to download an update client before launching the virtual world.

On the other hand, updates and patches usually mean a recompile of some SWF files on the web server. When users connect and load the virtual world, the web browser downloads the updated SWF files in the background and even without users' notice. This seamless update advantage lets developers deliver patches more easily and blur the whole update flow in users' view. The following screenshot shows virtual world data update loads automatically when a player logs in:

Connecting players in a virtual world

The core of a virtual world is multiplayer. Multiplayer means players need to connect to each other in order to interact in the virtual world. There are two main transport protocols in the Internet — TCP and UDP. We will have a brief discussion on them and then discuss the network model that connects computers.

A brief introduction to transport protocols

There are two main transport protocols that the computers use to deliver data from applications to the network and vice versa. They are Transmission Control Protocol (TCP) and User Datagram Protocol (UDP).

There are some main differences between TCP and UDP:

TCP provides reliable communication with error detection and recovery. The data delivered by TCP is in segments that are in order. TCP is used in most applications that require accurate data delivery such as WWW, e-mail, and file transfer. Except the latest Flash Real-Time Media Flow Protocol, all Flash connections used the TCP protocol.

UDP, on the other hand, does not have error recovery and does not guarantee the data is delivered and the order may not be in sequence. However, UDP is so simple that the header size is much smaller than TCP. The small header size and missing error recovery lets UDP give shorter latency and higher throughput. Thus UDP is often used in multimedia broadcasting applications that require faster delivery and allow transfer error.

Peer-to-peer

Peer-to-peer network means every machine connects to the other machine in the same network. In this network, every peer node listens to the requests and provides results to each other.

Recently in the Flash player 10.1, Adobe introduced the Real-Time Media Flow Protocol (RTMFP) that supports peer-to-peer connections between Flash clients on top of the UDP protocol. The Flash clients can rely on the Adobe status server, which is in Beta now, to locate and authoricate the peers or directly locate peers in the same local network.

One advantage of peer-to-peer network is that there is not a master computer. Every machine in the network does the same task and thus there is no single point of failure in the network. The network application keeps working when any machine downs.

Another advantage of the peer-to-peer network is that the latency between two computers is half compared to the client-server model of communication. The computers are communicating to each other directly instead of delivering the message by another computer in middle.

Peer-to-peer network is useful for multiplayer applications or games that divide the users into small groups. They can benefit from the peer-to-peer approach that computers in group are communicating directly to their targets and the network bandwidth used in each group will not affect the others.

However, there are some disadvantages that make it not suitable to use in a virtual world with massive multiplayer.

As there is not an administrative machine, every machine is the same and they all need to have a copy of all logic and data in local. Users will have access to all critical data and can easily modify the data without validation. Hacked clients can send out altered messages to other peers to cheat them. This raises the security problem that the hacked clients can claim to have unlimited health points or claim that all attacks are missed.

Moreover, every machine establishes connection with each other. This make the number of connections grow quadratically with the increasing number of nodes. There are a total of 5050 connections when there are 100 machines in the network. What if there are 1000 machines and 50,000 connections? Imagine that there are 100 players now in the virtual world and all 100 players are doing different tasks and then broadcasting to each other in every second. The whole network will be overloaded.

Another disadvantage is that the connectionless characteristics of UDP may make peer-to-peer connections fail on computers that are behind a firewall or NAT. The following diagram shows the peer-to-peer architecture:

Client-server network

Client-server network means there is a centralized server and every machine connects to this server. The server computes requests from client machines and provides results to client machines that need the results. What clients do is just send a request to the server and display the results. There can be few or even no logic in client side.

This network is usually used in virtual world because there are only N connections between N clients and the security is enhanced as most critical logic and data is in the server so that users cannot modify it themselves.

Take the previous 100 machines in Peer-to-peer section as an example. There are 100 players in the virtual world with the server-client machine now. When one player sends a broadcast message to tell others, the message was sent to the server and the server distributes the messages to all other 99 machines. The following diagram shows client-server architecture:

Clients need to keep communicating with the server to keep the whole virtual world synchronized among clients. There are two methods to keep the communication with the server — polling and socket-based.

Polling

Polling refers to the activity wherein the clients keep asking the server for updated status in an interval. It is usually used in multiplayer applications that do not have persistence connections. It could be a PHP chat application or chess game played by two players.

The implementation of this method is easy and thus may be used by developers who are new to multiplayer applications. However, we should not use this approach in Flash. Instead we should use the socket connection from Flash to establish persistent connections to the server.

In the polling approach, clients need to keep asking the server for an update even when there are no updates most of the time. This wastes a lot of bandwidth and greatly increases the server loading. It is a bad practice to use polling in massive multiplayer applications and we should avoid it throughout the development of the virtual world.

Take an example of how a turn-based Tic-Tac-Toe with polling performs poorly.

When two players connect to the server and are ready to start playing tic-tac-toe together, player A is thinking where to put an "X" on the board. When player B is waiting, his machine asks the server if there are any updates from other players per second. After a while, player A put an "X" in the middle of the board. Next when client B is asking the server, the server tells client B that there is an "X" in the middle now. Client B renders the "X" and now it is the turn of player B. The following figure shows polling in Tic-Tac-Toe:

During this process, client B keeps sending messages to the server and the server keeps responding to client B just to tell it that nothing happened. This dramatically increases the network loading and server loading. And this is just a two-players example. What if there are eight other players watching this game as spectators? Every player sends a message to the server and get a response message from the server in every second. Imagine there are 100 rooms and 10 players in each room. Now we are talking about 1000 messages per second just for asking the server if there is any update.

Moreover, there is an update latency problem in polling. When player A updates the board, player B knows the update from player A next time when his machine asks the server. This latency depends on the polling interval. A short interval improves the latency problem while putting more load on the server and network. A long interval with large latency makes it unacceptable for real-time interaction between players.

Another disadvantage of polling is the bad scalability. A server needs to keep responding to the polling clients that use relatively lots of system resources. This results in the server only being capable for a few concurrent connections. Usually a polling server supports up to 300 concurrent connections. I had an experience on creating a Flash multiplayer virtual world with .Net web service backend. Due to the limitation of the server, I had to use the polling approach and it would end up supporting less than 200 concurrent players.

The low concurrent players capacity of a server means it needs many servers to handle massive players' connections at the same time and makes it difficult to manage.

Therefore, polling may be suitable for very small-scale networks and it should be avoided in Flash virtual world.

Socket-based connection

In contrast to polling, a socket-based connection establishes persistent connections to the server. The server sends messages to clients only when it needs and vice versa. There are no more redundant messages such as a client asking the server if there is any update because server will push updates to clients without clients initializing the requests. This is also known as asynchronous socket or event-driven socket.

Take the same Tic-Tac-Toe example with the socket-based implementation. The following diagram illustrates the data flow between player A, B, and the server. There are only three messages in the whole process, player A communicates to the server to put an "X" on the board, player B renders the "X", and a successful acknowledgment of the server to player A. If there are eight spectators in the game, only around 11 messages will be sent to the network in this period instead of 18 messages per second. The following diagram shows event-driven Tic-Tac-Toe:

The event-driven socket-based connection eliminates the polling interval latency. The very low server loading enables almost real-time communication between players for which the latency only depends on the client's and server's Internet connections.

It also allows more concurrent players than the polling architecture and is therefore easier to scale. Normally a socket server can handle thousands of concurrent connections.

Socket server

Socket server for virtual world is an event-driven server application that handles clients' connections and manages the communication between clients.

When a user starts up and connects to the virtual world, the machine that the user uses is a client. The place where the client machine connects to is the server. The server can be one single powerful computer or a cluster of networked computers interconnected within a high-speed local network. The purpose of the socket server is to manage all client's connections and provide centralized logic and control to clients. It may also respond to provide and store persistent information for the virtual world such as user profiles or world state.

Unlike developing an offline single player game where all logic and data are placed in a SWF file, logic and data are distributed into different places in a virtual world.

Most critical game logic, such as business logic that handles virtual money transaction, is located in the server to enhance the security. The server is also responsible to handle all users' actions and behavior, and provides each user the information they need.

On the other hand, clients are in-charge to display the virtual world according to the client-side data and latest data that updates from server-side. Client-side data includes terrain, map, UI, and basic logic.

For example, imagine that there is a player standing in front of a fountain and you can see him in the virtual world. It is the client that renders the fountain sight according to your current position. And the client gets an updated message from the server that there is another player standing in front of the fountain and renders this player. The clients also gets the appearance of that player from the server in order to render it.

Available socket servers for Flash

There are several socket servers on the market that fit the development of Flash virtual world. Some are good at media streaming while some are powerful on user management.

SmartFoxServer

SmartFoxServer (http://smartfoxserver.com/) was developed by gotoAndPlay(). It is a socket server for Flash that provides powerful tools and resource management to enable highly productive development of virtual worlds and multiplayer games.

It was designed for Flash originally and now it also provides a set of API for iPhone, .Net, Java, Silverlight, and even Ajax. It also supports media streaming function by embedded open source Flash media server called Red5.

It also supports clustering through terracotta, an open source clustering software. The logic is distributed into clustered servers and enables the ability to extend the scalability and enhances the failure resiliency. The server comes with fully-documented resources with lots of tutorials for beginners. There is also an active forum to get support.

SmartFoxServer provides different licenses and connection options for developers. It provides Lite, Basic, and Pro options with maximum connections from 100 to unlimited. The Lite version is free with maximum 50 concurrent connections and Basic or Pro version are free for up to 20 concurrent connections. Also the Pro version provides an add-on module called BlueBox (http://smartfoxserver.com/products/blueBox.php) to allow connection behind firewalls and proxies via HTTP-tunneling.

However, it will be a little expensive as the server costs $2000 Euros for SmartFoxServer Pro and $400 Euros for the BlueBox add-on with unlimited connections.

ElectroServer

ElectroServer (http://www.electro-server.com/) is another mature virtual world server for Flash that was developed by Electrotank in 2001. Similar to SmartFoxServer, ElectroServer provides powerful tools and fits the development of Flash virtual world server.

ElectroServer also provides scalability by load balancing with multiple gateway servers. The gateway servers are used to handle the clients' connections I/O and the logic is kept in one server. ElectroServer also provides media streaming features.

There are two packages with different media connections and concurrent player options available. The costs of ElectroServer can be expensive. Prices start from $700 to $72K depending on the package option. The professional version is free up to 25 concurrent connections.

Flash Media Interactive Server

Flash Media Interactive Server (http://www.adobe.com/products/flashmediainteractive/) was developed by Adobe and aims to provide video streaming and real-time communication between different Flash player clients. Flash Media Interactive Server mainly targets real-time streaming and communicating technology that can stream videos with different popular codec and live stream. It supports features such as server-side ActionScript extension and server-side shared objects to make it possible for virtual world development.

This server provides clustering by edge/origin load balancing. Logic is kept in the origin server and clients connect to different edge servers, then edge servers connect to the origin server. It is like the gateway approach from ElectroServer.

However, the lack of game room management and game-related features means that developers have to write their own game management scripts.

Flash Media Interactive Server costs $4500 for unlimited connections.

Red5

Red5 (http://red5.org/) is one of the open source Flash socket servers that provides basic server-side features such as real-time protocol and shared memory. It aims to become an open source alternative of Flash Media Interactive Server and thus it is more powerful on video streaming than virtual world resources management.

Red5 uses edge/origin clustering that is similar to the Flash Media Interactive Server while using the open source Terracotta solution.

As an alternative of Flash Media Server, it also lacks server-side game management features. However, as it is open source, you can extend the functionality of Red5 to fit your idea of the virtual world.

Writing your own socket server

Most Flash servers in the market provide extensibility for developers. However, available servers may not fit your budget or design ideas. As an alternative solution, you can program your own socket server to handle Flash connections. The socket server is usually written in C++ or Java. What a virtual world server does is handle all connections and manage all zone, room, and user resources via a predefined protocol. There are some resources from Internet that discuss how to develop a socket server. There is an old article (http://gotoandplay.it/_articles/2003/12/xmlSocket.php