Revive a Browser Game ServerThe Open Unlight ProjectPhoto by Artem Labunsky on Unsplash
View Slide
WEB DEVELOPERGAME DEVELOPER࣌ݭ@elct9620
Ruby + ActionScript 3
Adobe Flash IDE is unavailable!
mxmlc src/Unlight.mxml
Unlight can be compiledby Flex SDK 3.x
Failed because missing files
Setup environment takes much time
The source code always become dirty
•Always reset client compile environment•Patches / Rework•Customizable Server/Client•Adjustable Docker compose configure
Secure Remote Passwordnot matched!
http://srp.stanford.edu/design.html
http://srp.stanford.edu/design.htmlStep 1. Client create PublicKey A
http://srp.stanford.edu/design.htmlStep 2. Server create PublicKey B and send it with Salt to user
http://srp.stanford.edu/design.htmlStep 3~. Compute SessionKey and verify other's Matcher
(/‵Д′)/~ ╧╧
24 Core CPU24G RAM98K IOPS SSD300M/100M FTTHSponsor by Poka
Feel "LAG" after 500 onlineplayers
(0.214518s)SELECT *FROM `card_inventories`WHERE (`card_inventories`.`chara_card_deck_id` = 2971)
src/model/card_inventory.rb
ALTER TABLEcard_inventoriesADD INDEXchara_card_deck_id(chara_card_deck_id)
About 100x faster
About 1000 online playerswithout "LAG"
•Adjust Cpuset to fix database on specify cores•Adjust Swappiness to prevent use disk•Adjust Full Table Index to cache small table
•Move Database outside Docker•Enable SR-IOV to use physics network card•Add partition to database
Estimate capability > 3000online players
•DAU about 500 online players•Rows grow fast Only two weeks we have 10M ~ 20M rows•1 Developer 1 DevOps 1 Player Support
But how to hosting this game?
Add CloudWatch to analytic online players
Open Unlight'sReword/Customize
Open Unlight'sAllow add customize gems
Tricks to allow Docker add optional files
customize/server/src/authentication.rb
customize/server/src/payment.ru
Use Rack to implementAPI server
Extend CLI to serve in docker
Hosting a game have to supportplayers resolve problems
SmartLook can replay player session to debug
ZenDesk can help players in one central system
•ZenDesk - Player support•SmartLook - Client Debug (for HTML5)•Asana - Issue Tracking•AWS - CDN/Monitoring•Discord - Co-working
The HTML5 version?
Flash will be removedat 2020 in Chrome
The Unlight client is Flash
But no one knows CPA willmaintenance or not
From TCPSocket to WebSocket
Client ServerPacketThe TCPSocket send packet directly
Client ServerPacketThe WebSocket send packet with WebSocket wrapperWebSocket
Unlight use EventMachinehandles connection
Comment out all EventMachine connection
Implement a Rack middleware with WebSocket gem
Add Rack's .ru and it can be served by Puma or Unicorn
We alreadymigrated 90% server toWebSocket
How the client communicateswith the server?
It convert data to a command
Each packet should have a header to describe command
JavaScript can create 2 bytestruct?
new Int8Array([0x00, 0x03, 0x00, 0x01,0x00, 0x0a])
You can learn howthe C programmer thinkby Unlight's Ruby source code
From Golang to WebAssembly
func AuthCmd(name string) []byte {buffer := new(bytes.Buffer)binary.Write(buffer, binary.BigEndian, uint16(1))binary.Write(buffer, binary.BigEndian,[]byte(name))return buffer.Bytes()}
GOOS=js GOARCH=wasmgo build -o libul.go
Convert Unlight toHTML5 is possible!
What the next?
Test! Test! Test!
We are trying to learn to host agame server as a programmer
And last ...
New security problem is coming!
Thanks