dconf21014 - mobile gameserver backend in d - stephan dilly

28
Mobile Gameserver Backend in D Stephan Dilly @Extrawurst 5/23/2014 Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 1 / 28

Upload: extrawurst

Post on 14-Jul-2015

1.187 views

Category:

Software


0 download

TRANSCRIPT

Mobile Gameserver Backend in D

Stephan Dilly

@Extrawurst

5/23/2014

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 1 / 28

Structure

1 The Author

2 STACK4

3 STACK4 Multiplayer

4 D at Funatics

5 Conclusion

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 2 / 28

The AuthorPersonal

Stephan Dilly

28 years old

Programming for 15 years

Game Industry for 7 years

Software Engineer at Funatics Software GmbH

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 3 / 28

The AuthorTrack Record

2007 The Settlers - Rise of Cultures (PC)

2008 Tom Clancy’s Endwar (NDS/PSP)

2009 24-Fun

2010 Cultures Online

2011 Ufo Online

2012 Panzer General Online

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 4 / 28

The AuthorD experience

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 5 / 28

The AuthorD experience

2006 First encounter with D

2007 First dmd bug report ;)

2008 Thesis about game development in D

2009 Multiple hobby projects

2013 STACK4 Server Backend

2014 FunNetX Server Backend Components

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 6 / 28

STACK4The Game

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 7 / 28

STACK4The Game

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 8 / 28

STACK4History

05/22/2013 Repo created

06/17/2013 First Release on Android

07/30/2013 Release on Blackberry10

12/18/2013 Added Online Multiplayer

05/13/2014 Release on iOS

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 9 / 28

STACK4 MultiplayerStructure

Requirements

Research

Vibe.d

Architecture

Implementation

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 10 / 28

STACK4 MultiplayerRequirements

Supports long polling (sockjs)

Fast and memory efficient

Compatible with our consumer server

Easy upscaling

Fast development process

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 11 / 28

STACK4 MultiplayerNodejs

Simple event driven io

great community (npm)

javascript, typescript

callback hell

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 12 / 28

STACK4 MultiplayerJava

statically typed

proven, huge knowledge base/community

vertx.io for evented io

big memory footprint in our case

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 13 / 28

STACK4 MultiplayerVibe.d - Introduction

Vladimir’s Talk at dconf2013

”Asynchronous I/O for maximum speed and minimum memory usage”

”Fiber based”

Simple RESTful services

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 14 / 28

STACK4 MultiplayerVibe.d - Comparison

1 va r h t tp = r e q u i r e ( ” h t tp ” ) ;2 va r f s = r e q u i r e ( ” f s ” ) ;3

4 ht tp . c r e a t e S e r v e r ( f u n c t i o n ( req , r e s ) {5 r e s . wr i t eHead (200 , { ’ content−t ype ’ : ’ t e x t / p l a i n ’ }) ;6

7 setTimeout ( f u n c t i o n ( ) {8 f s . a ppendF i l e ( ’ l o g . t x t ’ , ’ dat to append ’ , f u n c t i o n ( e r r ) {9 i f ( e r r ) throw e r r ;

10

11 r e s . end ( ”World ! ” ) ;12 }) ;13 } , 1000) ;14 }) . l i s t e n (80) ;

Listing 1: node example

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 15 / 28

STACK4 MultiplayerVibe.d - Comparison

1 impor t v i b e . d ;2

3 vo i d hand l eReques t (4 HTTPServerRequest req ,5 HTTPServerResponse r e s ) {6

7 s l e e p ( 1 . s econds ) ;8

9 appendToFi l e ( ” l o g . t x t ” , ” dat to append” ) ;10

11 r e s . wr i t eBody ( ” He l l o World ! ” ) ;12 }13

14 sha r ed s t a t i c t h i s ( ) {15 l i stenHTTP (new HTTPServerSett ings , &hand l eReques t ) ;16 }

Listing 2: vibe.d example

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 16 / 28

STACK4 MultiplayerBackend architecture

LoadbalancerSmartphone Firewall

UserDB (MySQL)

User

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 17 / 28

STACK4 MultiplayerLibraries

forever-d

sockjs-d

sockjs-unity3d-xhr

elo-rating-d

xtea-d

gcm-d/apn-d

find the libraries on github under https://github.com/Extrawurst/...

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 18 / 28

STACK4 Multiplayersyslogclient.log template

1 // b e f o r e2 l o g g e r . l o g ! ” event2 ” ( [3 ”param2” : to ! s t r i n g (12) ,4 ”param3” : to ! s t r i n g ( t r u e ) ] ) ;5

6 // a f t e r7 l o g g e r . l o g ! ” event2 ” (8 ”param2” , 42 ,9 ”param3” , t r u e ) ;

Listing 3: example

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 19 / 28

STACK4 Multiplayersyslogclient.log template

1 vo i d l o g ( s t r i n g event , T . . . ) ( i n T params ) {2

3 s t a t i c a s s e r t (T. l e n g t h % 2 == 0 , ”odd number o fpa ramete r s r e q u i r e d ” ) ;

4

5 i f ( m ur l . l e n g t h == 0)6 r e t u r n ;7

8 s t r i n g [T. l e n g t h ] paramArray ;9

10 f o r e a c h ( i , param ; params ) {11

12 paramArray [ i ] = to ! s t r i n g ( param ) ;13 }14

15 // s n i p : a c t u a l l o g g i n g . . .16 }

Listing 4: implementation

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 20 / 28

STACK4 Multiplayersyslogservice.equalComponents

1 // b e f o r e2 i f ( cu r r entT ime . y ea r != m lastFi leNameUpdateTime . y ea r | |3 cur r entT ime . month != m lastFi leNameUpdateTime . month | |4 cur r entT ime . day != m lastFi leNameUpdateTime . day | |5 cur r entT ime . hour != m lastFi leNameUpdateTime . hour )6 {}7

8 // a f t e r9 i f ( ! equalComponents ! ( SysTime , ” yea r ” , ”month” , ”day” , ” hour ” ) (

cur rentTime , m lastF i leNameUpdateTime ) )10 {}

Listing 5: example

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 21 / 28

STACK4 Multiplayersyslogservice.equalComponents

1 boo l equalComponents (T,COMPONENTS . . . ) (T a , T b ) {2

3 f o r e a c h ( comp ; COMPONENTS) {4

5 s t a t i c a s s e r t ( i s ( t y p e o f ( comp) : s t r i n g ) ,6 ” components must be s t r i n g ” ) ;7

8 s t a t i c a s s e r t ( t r a i t s ( comp i l e s , m ix in ( ” a . ”˜comp) ) ,9 ” ’ ”˜comp˜” ’ i s not a member o f ’ ”˜T. s t r i n g o f ˜” ’ ” ) ;

10

11 mix in ( ” i f ( a . ”˜comp˜”!= b . ”˜comp˜” ) r e t u r n f a l s e ; ” ) ;12 }13

14 r e t u r n t r u e ;15 }

Listing 6: implementation

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 22 / 28

STACK4 MultiplayerMsgType send/parse enhancement

1 // b e f o r e2 i f ( a r g s . l e n g t h == 3) {3 i n t paramJoin , gametypes ;4

5 i f ( t r yPa r s e ! i n t ( a r g s [ 1 ] , paramJoin ) &&6 t r yPa r s e ! i n t ( a r g s [ 2 ] , gametypes ) )7 { . . . }8 }9

10 // a f t e r11 t r y {12 auto r e s = parseMsg !MsgMatchMake ( a r g s [ 1 . . $ ] ) ;13 . . .14 }15 ca tch ( MsgParseExcept ion e ) { . . . }

Listing 7: example

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 23 / 28

D at FunaticsD components

webapi

loginapi

clientconfigapi

syslogservice

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 24 / 28

ConclusionWhat rocks

Performance

Build speed

Syntax,Templates

Mono-D

Vibe.d and DUB

we had an itch - so we scratched it

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 25 / 28

ConclusionWhat rocks not so much

GC in Phobos

Exceptions in vibe.d

GUI

Debugging on windows

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 26 / 28

ConclusionFuture directions

D in STACK4

D at Funatics

D Games using Amazon AppStream (maybe using aurora?)

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 27 / 28

Thank you for your attention!

Stephan Dilly (@Extrawurst) #dconf2014 5/23/2014 28 / 28