Magic Academy Tech Design Document

gasownerΔιαχείριση Δεδομένων

31 Ιαν 2013 (πριν από 4 χρόνια και 7 μήνες)

242 εμφανίσεις

Magic Academy Tech Design Document

1




Magic Academy Tech
Design
Document




By Joe Zhu

joe_zhu@cahcn.com


Date

Verion

Details

Comment

2012
-
1
-
20

0.0.1

A
bout MA

猠慲捨楴散e畲攮


























2

Trillion Game

Studio



CONTENTS


CONTENTS

................................
................................
................................
................................

2

§1 Introduce the Magic Academy

................................
................................
.....................

3

§2 The technology request of the Magic Academy

................................
....................

4

§3 The
architecture of the
Magic Academy

................................
................................
.

5

Game’s Client End

................................
................................
................................
.........

5

Server
................................
................................
................................
................................
.

9

§4 Magic Academy’s technology point

................................
................................
........

13

Network communication

................................
................................
........................

13

Data s
ecurity

................................
................................
................................
................

14

Script system

................................
................................
................................
...............

14

Summary

................................
................................
................................
................................
.

15

Reference

................................
................................
................................
................................

16


Magic Academy Tech Design Document

3



§
1
Introduce the
Magic Academy

Magic Academy is designed as a high graphics quality Text Role
-
Play
-
Game.
Game play
ers could has the

experience about chatting with friends, playing the
game story, fighting against other players

in

the game.

4

Trillion Game

Studio



§
2

The technology request of the
Magic Academy

The major aim of the Magic Academy is helping player to play the game
-
play,
finish the game story
and keep in touch with their friend by using game’s
network.


The game client end
’s

main function is:



Register or Sign in onto the remote game server by using apple ID or device
ID in apple device.



Check and download the newest game data on the game’s FTP

servers.



According to the newest game story script, player is going to finish the
game
-
play story.



Ha
v
ing the PvP event with other online player for
winning
some bonus or
los
ing
some
self
-
interest
.



Player could

use virtual money to

pur
chase

the goods
likes equipment, item
or medicine
, etc.


The game server’s main function is:



Accepting and deal with the register/sign in request from game client.



Help updating game
-
play content



Updating
player’s profile.



Implementing game’s network game
-
playing logic.



Feedback and judge the
legality
of the request data from the client program.



Security the game data in the server end.



Query and update the Database.


Magic Academy Tech Design Document

5



§
3
The
architecture

of the
Magic Academy

According to the description about the request of Magic Academ
y in the
previous chapter, we can
conclude
the considerable

architecture about the game
list below
.

Game’s Client End

The request of the client design is:



The game state machine

management

system

with

its

states

collection



The entity
management
system

with its entit
ies



Script system



The message distribute system



The resource
file
management system



The Network communication system



Input/output system



Memory
manager

system



The set of
utilit
ies

in the game


The game state machine management system with
its states collection

In architecture of the whole game, the state machine is key system. Many
parts of the program use the limited state machine, likes the HUD flow control,
task system, Artificial

Intelligence (
AI)

system, etc.

So, we need build a genera
l,
reusable state machine system, and then

make it suitable usage in some specific
conditions in the program.

A common abstract interface of the state manager is
necessary.

And we make state machine work around current sub state which we
had set.

6

Trillion Game

Studio


The entit
y management system with its entities

We can consider everything
in the virtual world as the

entity, including the
player character, event,
trigger point and level gear, etc.
The entity all has some
attributes likes,



Artificial Intelligence



Physic attribut
ion



The relationship of each event


We can update every entity to implement the game logic by using entity
manager system in
one piece

logic turn. But how could we construct the whole
entity world? We

need a
entity factory

to do the job.

And also we need other RAD
tools to design the game virtual world. The RAD tool exports the binary file or the
script fi
le, which used by Magic Academy game.


Script System

According to the game
-
play design in the Magic Academy, the script system
is very
important for describe the virtual game world. The script world should
include the function likes,



To describe the details of the game world



To describe the detail of the task



To describe every attribute of the
NPC

in the game



To describe the attributes
and the skills of the players



To describe

every detail
of the each item and each weapon, also including
where

and when could player get it.

And what type of script system should we use in the Magic Academy, I think
that the Lua is the best
choice
, which is

a light
-
weight script programming
language.

In the program, we embed Lua into the every game
-
play entity and
game state machine system. And
using Lua to implement
s

some game
-
play logic
.

We need to pre
-
compiled the Lua

script files for reverse
-
engineering,

and
Magic Academy Tech Design Document

7


prevent 3
rd

partner by modifying our game.

In addition, the server end can keep
the client server’s
safety
.

The message distribute system

Each entity connects with each other directly or indirectly all by the
message distribute system. This system mak
es whole virtual
world working
perfectly. Each entity sends the message to another by the message distribute
system.

From the comment listed above, we can conclude that there is a close
relationship between the en
tity manager

system with the message distri
bute
system.

Any standalone system is useless in the game. So, we should register the
message distribute system in the entity manager system, and make every entity
can be responded by message call.

The resource file management system

The main function
ality

of the resource file manager system is to let game call
the same resource file input/output interface, including manage the game’s
record files.

But the Magic Academy’s content has the limited size, some
resource
file should be deposit on the remote serve
r. And game program could
download

these resource files from the game server when it is in the loading progress.

By the way, all resource files in the game should be packed, any standalone
file

with known or unknown formation

is not allowed.

The Network co
mmunication system

The network communication system is one of the essential modules in the
Magic Academy’
s architecture
. T
he main functionality i
s to connect to the game
server
, send the packed data to the server and receive the result data to
rebuild vi
rtual game world.

8

Trillion Game

Studio


Input/output

system

The primary functionality of the I/O system is to
unify the

player input

interface between game program and the variable game device

by encapsulating
the input/output detail.

And send the I/O data to the game logic mod
ule.

Memory m
anage
r

system

The memory manager system

is basic module in the program
. For optimize
the game speed and prevent memory leak problem, we using a memory manager
system to manager the memory usage, monitor the memory leak problem,
garbage collect
ion, etc.


And memory manager system can help developer to debug the program
,

too.

The set of utilities in the game

The utilities
including math library, string operation function, operation
system related function and other many macros
definition.

The
whole client system’
s architecture is listed in the chart blow.


Magic Academy Tech Design Document

9


Server

In this MMO TRPG,
the hard core content is store in the game server, and the
server implements the game logic,
do the game logic judgment and run the logic.

So the game server has the highest
run
-
time stress i
n whole system.

The server’s
functionality contains,



Allow player finishing register progress and sign
-
in the server.



The number of the visitor section hit the highest
level in same time.



Inquiring and updating Database is
bottleneck
.

+
OnUpdate
() :
void
<<
interface
>>
IStateBase
+
Update
() :
void
CStateManager
+
OnUpdate
()
CStateSub
1
*
+
OnUpdate
() :
void
+
OnRender
() :
void
+()
<<
interface
>>
IEntity
+
Update
() :
void
+
Render
()
CEntityManager
+
OnUpdate
()
+
OnRender
()
+
OnMessage
()
CEntitySub
1
*
+
CreateEntity
() :
IStateBase
<<
interface
>>
IEntityFactory
1
1
+
Create
() :
IStateBase
CEntityFactory
+
SendMessage
() :
void
CMessagePump
1
1
*
*
+
OnMessage
()
<<
interface
>>
IBeNotified
10

Trillion Game

Studio


In terms of server
-
si
de,
stability, security, responsiveness is very important
.
From this point of view, server
-
end

n
eed
s

to be divided into several parts,



Gateway server



Game server



Register
, sign
-
in server



File update server



Database access server



Database

Gateway server

As
the

game
,

it
-
self

on efficiency

and speed

of the

special

demands to

the
server
,

has a

high

responsiveness
,

high

capacity

network

interactivity,
and void
game server respond to client
-
side connection request job. S
o we need

to
set
up

multiple

front
-
end

gate
way

server

on the
server

cluster
,

according to

the
different

functions,

these

gateway

servers

can be divided into

several server
likes,



Register, login gateway server



Game logic gateway server



Game file update gateway server


The main purpose of

these

is
the

gateway server

to
accept

requests

from

client, and to

record these requests.

These requests

will
be

distributed to

the

feature

game

server

in the server
clusters
.

These request
s
will be
completed

within

the

server cluster

and return to the gateway serv
er. The
gateway server
receiv
es

the
result

data

and distribute
s

these results

to the client.

Game server

Game server is

the core

function of

the

server cluster
s
,

and
its
internal

functionality

can be divided into

multiple

server

program
s
, for example,

Magic Academy Tech Design Document

11




Responsible for

all
players

interactive

scenes

-

scenes

server



Responsible for

each specific

scene

of NPC

-

AI

server



Responsible for script system


script server



Responsible for chat, e
-
mail or any kinds of communication between players


communicate ser
ver



Responsible for store players’ data


DB server

As the game

within the

direct sales

efficiency requirements,

each

server
using

socket protocol

to connect each server

program

in
the server
-
side
.

Register
, login server

Register/login

server is

to complet
e

regist
er

or

log
in

the
player's

account
.

The progress of the
registration, login

action is independent
from game main logic, so we separate this functionality as
an

independent server
.

And register, login server needs
database

server

to support
.

File upda
te server

File

update server's main task is

to
help
the

client
-
side to
update

the game

data

resources.

File

update

operation

has nothing to do with the main game logic,
so this operation is no need to take up the game server’s
data
throughput

capacity
.

So
client
-
side program

can

update

its resource file from the
file

update

server.

For

access
ing

to the server
-
end

while

the client

does not
require

certification

by

the user

database.

Database access server

The main functionality of Database access server is D
BMS, its main purpose
is provide data service to the upper structure of registration server, login server,
game logic server.

12

Trillion Game

Studio


Database

Database

stores

every detail in the game

and

server

to

provide

data to
support

the last

function.

The whole server’s arch
itecture is look like,

Server Group
(
internal
)
Server Group
(
Front end
)
Game Update
Server
Register
&
Login
Server
Game Logic Server
AI server
(
optional
)
Scene Server
DBMS
Gateway server
#
1
Gateway server
#
2
Internet
DB
Register
&
Logic
Gateway
Magic Academy Tech Design Document

13



§4
Magic Academy’s technology point

From the
comment of the
architecture, we
can find out that the network
communication system is the most complicated system
in the entire

Magic
Academy

program.

And the server
ensure
s

the whole system runs

security
and

high

data

throughput,

and

the

script system

are

both

used

in the

client
-
side
and the server
-
side
. All these works
will be

the more difficulty key point in

the
entire software

system
.

Network
communication

Network system is consisted with two parts, the communication between
client
-
side and server
-
side, and the communication operator among several
servers in
the
server

cluster
s
.

Between t
he c
lient
-
side
and the

server

cluster
s
.
In contrast, its
communication requirements will not very strict.
A little of lost package is
allowed. So, we can use TCP/UDP network protocol in this communication
system
,

e
special

for some
speed priority operation.

But MD5
Verification

algorithm

is needed in whole communication progress.

Server
-
end

need
s

to

take into account

to verify

all

the data

from the client
, which is

to avoid

players

cheating.

Within the server
-
clusters,
all communication among servers,
in order
to

ensure that the data

thro
ughput,

are based on

socket

protocol
between
the

way.

At the same time

we

should

take note of

the problem

on the server
side

development
:

Data
c
opy
ing
.

Using memory reference counter

and avoiding copy data
f
requent
ly. Keep ZERO data copy.

Context
switch
.
T
he gateway server buffers up the data, request from the client,
delivers the data to the other game server to work from the request buffer.

14

Trillion Game

Studio


Memory allocation.

In the specific run
-
time environment,
especially

the
server
-
end program,
efficiency

is one of the most important
things

to do.

In old
time, we already know that memory
allocat
e
/deal
locate

operation
is fast way.
But in network programming field, calls memory operation frequently will cost
many CPU circles.

The main reason for that is
the
instantaneous probability of
emergence of multiple memory operations is still very large.

So pre
-
allocate a big
enough memory pool is necessary.

Lock Contention
.
An efficient planning of the lock mechanism, the degree of
difficulty is very high. Locking gr
anularity is too coarse, parallel operation will
lead to serialization; and fine
-
grained locking mechanism, most likely in time
consumption and space requirements, and are unnecessary consumption, the
efficiency of the entire server
-
side the underground.


Data security

T
he fairness in MMO game is very important, the same, the security of the
data is very important too. So, because of this, every data packets exchanged
between the server and client need to be MD5 checksum and avoid be tampered
by cracker.

Sa
me time, the game logic data from client program

is

need
ed

to be
v
erified

that

legal.

Script system

Script in the Magic Academy in the system may be a core content. The
reason is that the content or part of the NPC from the game or the game
description of

the event, the script will need to implement the system.

Magic Academy Tech Design Document

15


Summary


16

Trillion Game

Studio



Reference

1


佚名,《
MMORPG
服务器端架构和设计


ppt

2


Jeff
Darcy
, 《 高 性 能 服 务 器 架 构 》 ,

http://pl.atyp.us/content/tech/servers.html

3


GoF



Design Patterns:
Elements of Reusable Object
-
Oriented Software


4


Lua,
http://www.lua.org/

5


Boost::Asio,
http://asio.sf.net

6


PostgreSQL,
http://www.postgresql.org/