Sei sulla pagina 1di 44

Game server development in node.

js

Charlie Crane
@xiecc
Who am I

 NASDAQ: NTES

 Senior engineer, architect(8 years) in NetEase Inc. ,


developed many web, game products

 Recently created the open source game server framework in


node.js: pomelo
Agenda
 The state of pomelo
 Motivation
 Framework
 Practice
The state of pomelo

Fast, scalable, distributed game server


framework for node.js

Open sourced in 2012.11.20


Newest version: V0.6

https://github.com/NetEase/pomelo
Pomelo position

 Game server framework


 Mobile game
 Web game
 Social game
 MMO RPG(middle scale)

Realtime Multiple User Interaction


 Realtime application server framework
State of pomelo
 Pomelo is not a
single project
 Almost 40 repos in total
Framework ---
https://github.com/NetEase/pomelo
Success stories
 Chinese mythology
Community
Agenda
 The state of pomelo
 Motivation
 Framework
 Practice
Motivation--node.js and game
server
Node.js is a platform built on Chrome's JavaScript
runtime for easily building fast, scalable network
applications. Node.js uses an event-driven, non-
blocking I/O model that makes it lightweight and
efficient, perfect for data-intensive real-time
applications that run across distributed devices.

 Game Server
Fast Scalable
Network Real-time
Motivation--node.js advantages
 Scalability -- event driven I/O
 Game, network-insentive, massive network flow

 Language, javascript
 Browser, HTML5, unity3d, cocos2d-x, other platform – same
language in client and server

 Multi-Process, Single thread


 No lock
 Simple logic

 Lightweight, development efficiency, really quick iteration


Motivation–node.js disadvantage
 Some CPU sensitive actions
 Path finding
 AI

 Solution
 Optimization
 Divide process
 All can be solved in practice
Node.js game—Mozilla BrowserQuest
Node.js game—google gritsgame
Motivation -- our demo
http://pomelo.netease.com/lordofpomelo
Motivation--architecture of demo
Motivation -- game VS web
 Long connection VS Short connection
 Partition: area based VS Load balanced cluster
 Stateful VS Stateless
 Request/broadcast VS Request/response
Motivation--complicate servers
 Game VS web
Motivation--how to solve complexity
 Too … complicated?

solution: framework
Agenda
 The state of pomelo
 Motivation
 Framework
 Practice
Pomelo Framework

The essence of pomelo:

A distributed, scalable, realtime application


framework.
Framework --- design goal
 Abstract of servers(processes)
 Auto extend server types
 Auto extend servers

 Abstract of request/response and broadcast/push


 Zero config request
 Simple broadcast api

 Servers communication---rpc framework


Framework --- server abstraction

master

backend
frontend

backend

backend
frontend
backend
Framework--- server abstraction
Duck type

conn area
ector chat

frontend backend status


Server abstraction

The
Duck

servers
Framework---server abstraction
Framework --- request abstraction
 Client call remote method on server
 Client, like ajax

 Server, like web mvc framework


Framework --- request abstraction

Pomelo
component Connector
Loader

MQTTConnector SIOConnector HybridConnector

Mobile client Socket.io client Socket, websocket


client
Framework -- request abstraction

Support socket.io and socket in one project

Socket.io

Socket/We
bSocket
Framework --- push&broadcast
 Push messages to a group of users

channelService.pushMessageByUids(msg, uids, callback);

var channel = channelService.getChannel(‘area1’);


channel.pushMessage(msg);
Framework -- rpc framework
Framework – rpc framework
 Why rpc is so easy in pomelo?

 Thrift
 Writing a .thrift file
 Generate Thrift file to source code
thrift --gen <language> <Thrift filename>
 Copy the source to application

 Pomelo—start up, all done


 Client and server in one project
 Servers folder convention
 Auto generate proxy and remote on start up
Agenda
 The state of pomelo
 Overview
 Framework
 Practice
Practice --- simplest player move

client1 1、Move Area1


request
2、Forward
3、Move
connector
client2 Handler
4、Backward

… 5、Broadcast
1.5

clientn 6、Play move


animation Route rule

client
Practice --- Client Move Request

… find path, move animation


pomelo.request(’area.playerHandler.move’,
{path: path}, function (result){

});
Practice --- area server handler

handler.move = function( msg, session, next) {


… verify path
… handle move, add move action to tick
channelService.pushMessagesByUids(
route:’onMove’,
….);
next(null, {pos: playerPos, code:OK});
}
Practice --- client play move

pomelo.on(‘onMove’, function(data) {
play move animation

});
Practice – route rule
Define once:
app.route(‘area’, routeUtil.area);
Practice --- character move
 Character Move, isn’t that easy?

In reality , it’s hard


Practice --- handle move
 Different situations
 Player move, mob move
 AI driven or player driven

 Smooth effect
 Client prediction
 Latency Compensate

 How to notify
 AOI(area of interest)
What’s more
 Performance
 Plugin, components
 Realtime application framework – a better one, more
scalable, adaptable
 AI – pomleo-bt
 Broadcast strategy – pomelo-aoi , schedule
 Data sync strategy – pomelo-sync
 Admin all the servers -- pomelo-admin pomelo-cli
 How to build a full game – lordofpomelo play online
 High availability – master and zookeeper
Thank you
@xiecc
https://github.com/NetEase/pomelo

Potrebbero piacerti anche