55
1 / 55 Inside Tibia The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer, CipSoft GmbH

Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

  • Upload
    others

  • View
    30

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

1 / 55

Inside TibiaThe Technical Infrastructure of an MMORPG

Matthias RudyHead Programmer, CipSoft GmbH

Page 2: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

2 / 55

Tibia

2D fantasy MMORPG for PConline since 7 January 1997commercial since 5 November 2001free to playoptional subscription (7.50 Euro for 30 days)some paid extra services

world transfer, name change, but no ingame items

two clientsstand-alone client for Windows and Linux

Flash based client for browsers since June 2011

Page 3: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

3 / 55

Stand-Alone Client

Page 4: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

4 / 55

Flash Based Browser Client

Page 5: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

5 / 55

Some Big Numbers

~150,000,000 page impressions per month~20 terabyte web traffic per month~55 terabyte game traffic per month77 game worlds~1,200,000 game logins per day~500,000 different characters per day~300,000 different accounts per day95,000 active monthly subscriptions

Page 6: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

6 / 55

Some Small Numbers

People working on Tibia (in average) 3 product managers

4 programmers

4 game content designers

1 graphic artist (2D)

2 software testers

3 system administrators

3 community managers

9 customer support

representatives

Page 7: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

7 / 55

Architecture

Page 8: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

8 / 55

Servers: Default Hardware

IBM BladeCenter2 power supplies

2 network switches

2 huge fans

14 blade servers2 cores at 2.5 GHz4 GB ECC RAM2 hard disc 70 GB each in RAID2 network cards

CentOS 5.6

Page 9: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

9 / 55

Servers: Locations

own servers in Germany4 BladeCenter in Frankfurt

near DECIX

1 BladeCenter in Nurembergnear office in Regensburg

rented servers in USAhardware requirements similar to BladeCenter

in Houston and Dallasnear North and especially South America

some spare blade servers as reserveonline but unused

Page 10: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

10 / 55

Databases

Page 11: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

11 / 55

Databases: Hardware and Software

one big database24 cores at 2.4 GHz128 GB ECC RAM mirrored (64 GB RAM)

four smaller databases8 cores at 2.9 GHz24 GB ECC RAM

all of themstorage area networkCentOS 5.6PostgreSQL 8.4no clustering, no mirroring

located in Nuremberg

Page 12: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

12 / 55

Databases: Data

one big databaseall account data

partial copy of character data

four smaller databaseswebsite data

statistics, etc.

volatile data"who is online" list, etc.

management dataserver lists, IP addresses, etc.

forum data

Page 13: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

13 / 55

Databases: Software Choice

do not guess database performance, measure it!with realistic-as-possible data

structure

size

we measured in 2005copy of data and recorded requests from live system

PostgreSQL 7 vs Oracle RAC vs IBM DB2

PostgreSQL was slightly faster and a lot cheaper

reasonsall data in RAM (back then 6GB, now 25 GB)90% simple read operations (SELECT)

Page 14: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

14 / 55

Query Managers

Page 15: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

15 / 55

Query Managers

custom server softwareintermediate layer in front of databases2 of themphysically right next to databases

Page 16: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

16 / 55

Query Managers: Advantages

faster processing of requests from other serversthere is the Atlantic Ocean (150+ ms)

sometimes several SQL queries for request

sometimes C++ based logic for request

query managers physically right next to databases

hiding data allocationstores data in appropriate database

other servers don't care

simulates distributed database

not easily possible with PostgreSQL

Page 17: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

17 / 55

Query Managers: Advantages

additional access controlno direct access from web servers to database

no commodity software

defined requests with strict syntax

different access rights for different serversweb servergame serverpayment server

profilingcount types of requests

measure times of requests

Page 18: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

18 / 55

Query Managers: Disadvantages

yet another layerimplementation

testing

administration

point of failure

limitsamount of connections

amount of requests

etc.

Page 19: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

19 / 55

Query Managers: Connections

opening connections to all databases at startupaccepting connections from other servers

TCP/IP

SSL encrypted

proprietary binary protocol

Page 20: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

20 / 55

Query Managers: Code

written in C++30,000 LOC (lines of code)

5,500 LOC Tibia's shared code

28,000 LOC CipSoft's network and utility library

SQL statements only in this serverprepared queries wherever possiblestateless (after authorization)multithreaded

Page 21: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

21 / 55

Game Servers

Page 22: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

22 / 55

Game Servers

1 game world runs on 1 blade server77 game worlds

half located in Frankfurtnear to DECIX

half located in Dallasnear to North and South America

simulation of the game worldmaximum of 1050 characters online

formerly restricted by CPU load

currently restricted by game world sizegame design decision

Page 23: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

23 / 55

Game Servers: Data Distribution

account data in databasecharacter data local on hard disc

one (proprietary) text file per charactersome of it copied into database for use on websiteloaded on demand (character login)daily backup

world data local on hard disc~1,700 (proprietary) text files for definitions (~15 MB)~17,500 (proprietary) text files for world map (~300 MB)same again for "current" version of world mapeverything loaded at game server startup

daily backup

Page 24: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

24 / 55

Game Servers: Connections

opening 10 connections to query managers at startup

TCP/IP

SSL encrypted

proprietary binary protocol

accepting connections from clientsTCP/IP

RSA encrypted login request

XTEA encrypted afterwards

proprietary binary protocol

Page 25: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

25 / 55

Game Servers: Code

written in C++45,000 LOC

5,500 LOC Tibia's shared code

28,000 LOC CipSoft's network and utility library

multithreaded......except the whole world simulation

Page 26: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

26 / 55

Game Servers: Code

origin of world simulation in age of single CPU coreadvantage

no synchronization within world simulation

disadvantagesdoes not scale

limited by performance of one CPU core

the plan so farkeep world simulation as it is

offload anything else in supporting threads

think about it for the next game...

Page 27: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

27 / 55

Game Servers: Code

supporting threadsacceptor/receiver/sender threads

epoll, edge triggered, BSD socketsefficient on Linuxnot efficient when using OpenSSLdefault model in our network libraryour solution, there are others

Google "The C10K Problem"

reader/writer threadsmain thread shall not block on hard disc i/o

RSA decryption threadintentional bottleneck against denial of service attacks on CPU

Page 28: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

28 / 55

Login Servers

Page 29: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

29 / 55

Login Servers

custom server required for stand-alone clientclient updateaccount authenticationcharacter selectionguidepost towards game servers regarding IP addresses

5 of them1 in Nuremberg2 in Frankfurt2 in Houston

10 DNS entriesin 2 domains (login01.tibia.com, tibia01.cipsoft.com, etc.)

hardcoded in clients

Page 30: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

30 / 55

Login Servers: Connections

opening 10 connections to query managers at startup

TCP/IP

SSL encrypted

proprietary binary protocol

accepting connections from game clientsTCP/IP

RSA encrypted login request

XTEA encrypted afterwards

(simple) proprietary binary protocol

Page 31: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

31 / 55

Login Servers: Code

written in C++6,000 LOC

5,500 LOC Tibia's shared code

28,000 LOC CipSoft's network and utility library

statelessmultithreaded

Page 32: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

32 / 55

Game Clients

Page 33: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

33 / 55

Game Clients: Stand-Alone Client

Windows XP / Vista / 7Windows 95 / 98 / ME / 2000 until July 2011Linux27 MB installerautomatic update (over login server)storing data on hard disc

object definitions and images: 50 MBdiscovered mini map: up to 200 MB

written in C++63,600 LOCsingle threaded

Page 34: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

34 / 55

Game Clients: Flash Client

browser based client1.5 years of developmentavailable since June 2011still has "Beta" labelautomatic update (over web servers)caching data in Flash cookies

object definitions and images: 40 MBdiscovered mini map: up to 200 MB

written in ActionScript366,000 LOC and growingsingle threaded

Page 35: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

35 / 55

Game Clients: Connections

opening 1 connection......first to login server...and later to game server

TCP/IP

RSA encrypted login request

XTEA encrypted afterwards

proprietary binary protocol

Page 36: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

36 / 55

Encryption: RSA

asymmetric encryption with RSAwell known algorithm

secure enough

open source implementation without dependenciesnot OpenSSL library (too big)

1024 bit key

public key hardcoded in game client

private key hardcoded in game server

used for login requestto login serverto game server

Page 37: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

37 / 55

Encryption: XTEA

symmetric encryption with XTEAwell known algorithm

secure enough

fast

open source implementation without dependencies

symmetric keycreated by clientwrapped into login request

used for everything except login request

Page 38: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

38 / 55

Encryption: ISAAC

random number generation with ISAACsecure enough

open source implementation without dependencies

never ever use rand() function for anything remotely

related to encryption!

Page 39: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

39 / 55

Encryption: Connection Handling

Game Client Login ServerGame Server

time stamp + random number

(not encrypted)

time stamp + random number, credentials, XTEA key

(RSA encrypted)

payload

(XTEA encrypted)

TCP/IP connection

Page 40: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

40 / 55

Encryption: How We Failed

fail #1used rand() function

got XTEA keys brute-forced

fail #2used no time stamp + random numbergot attacks by replaying (MITM) recorded login packets

fail #3swapped p and q in server side implementation of RSA

got private key cracked

conclusionanything in encryption not 100% correct......your whole encryption breaks

Page 41: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

41 / 55

Web Servers and Load Balancers

Page 42: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

42 / 55

Web Servers and Load Balancers

websiteinformation

client downloads (stand-alone client)

client data (Flash client)

statistics

account managementaccount creationcharacter creationguild managementhouse managementpayment

forum

Page 43: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

43 / 55

Web Servers and Load Balancers

17 static web servers13 http, 4 https

located in USA (cheaper web traffic)

Apache 2.2

9 dynamic web servers7 http, 2 https

located in Germany (near to databases)

Apache 2.2

PHP 5.3

6 load balancersLinux Virtual Server

Page 44: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

44 / 55

Content Delivery Network

big change in April 2011no more static web serversonly 2 load balancers leftnow using a content delivery network

hosts and caches all static web content

reroutes and caches all dynamic web content

Akamai

Page 45: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

45 / 55

Content Delivery Network

advantagesshorter load times of static web content for customers

no need for extra server capacity during peak times

better protection against DDoS attacks

all in all ~60% cheaperless server rental costsless administration costs

disadvantagesinitial setup (not that big)

their system, their rules

update of cached data not instant (obviously)

Page 46: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

46 / 55

Payment Server

Page 47: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

47 / 55

Payment Server

handling data exchange with payment provideraccepting connections from query managers

TCP/IP

SSL encrypted

proprietary binary protocol

written in C++11,000 LOC

5,500 LOC Tibia's shared code

28,000 LOC CipSoft's network and utility library

stateless (after authorization)multithreaded

Page 48: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

48 / 55

Firewalls

Page 49: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

49 / 55

Firewalls

3 big hardware firewallsone for each location

NurembergFrankfurtDallas/Houston

every server behind one of those

purpose: defence against packet rate DDoS attacks

1 small hardware firewallin front of payment server

required for PCI-DSS

purpose: defence against web vulnerability attacks

Page 50: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

50 / 55

Distributed Denial of Service Attacks

information known to userslist of users online (from website)

IP address of game server (after login)

impact of DDoS attack on game serverinterrupts connections

of all users of game serverof all users of datacenter (if big enough)

but whyyyyy?disconnect in Tibia = usually character death = XP loss

ingame conflicts

because they can

Page 51: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

51 / 55

Lessons Learnt

intended architecture improvements for next gamebetter resistance against DDoS attacks

by design, not just by bigger firewalls

better multithreadingno big, undivideable thread

better scalabilitycloud style

well known formats instead of proprietary onesXMLJSONetc.

Page 52: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

52 / 55

Next Game Architecture

Internet

Game Clients

Dispatcherreachable from Internet

Game Serversnot reachable from Internet

Databasenot reachable from Internet

Page 53: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

53 / 55

Next Game Architecture: Advantages

DDoS attack on dispatcher less harmfulno direct impact on game servers

disconnects unknown group of users"unknown" is the big advantagethe more dispatchers the less impact

disconnected users have only small drawback ingamegame design related

disconnected users can instantly reconnect using any other dispatcher

dispatchers and game servers could be in the clouddispatchers could be run on plenty locations worldwide

Page 54: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

54 / 55

Next Game Architecture: Disadvantages

more layersmore implementation, testing, administration

more latency

independency of game servers required for scalabilitygame design restrictions

latency must not be that important

disconnect must not be that painful

Page 55: Inside Tibia The Technical Infrastructure of an MMORPGtwvideo01.ubm-us.net/o1/vault/gdceurope2011/slides/... · The Technical Infrastructure of an MMORPG Matthias Rudy Head Programmer,

55 / 55

Thanks!

[email protected]://www.cipsoft.comhttp://www.tibia.com

We're hiring!gamescom

"Jobs & Karriere"hall 8 booth B40

http://www.cipsoft.com/jobs