c++ - Is it possible to do real time network games in Actionscript 3.0 -
question: possible update 100+ objects in flash player on socket connections? more details , own try's below!
details
for internship got time create multiplayer physics game. worked steady 3 months on it. internship coming end , couldn't finish game.
my problem hard send multiple packets each time-step server , back. packets send position updates of objects , mouse of other clients.
i try explain network/game flow.
- client connects server using binary socket class in as3
- server ask verification , client sends name , thumbnail.
- server waits until 4 clients connected (some matchmaking etc)
- server picks 4 clients , makes them run on separate thread(combined team)
- client sends performance score server range 1-100.
- server makes best client host machine physics , other 3 slaves
- host game sets level , makes around 1-100 shapes in level(primary shapes , complex shapes bridges, motors, springs)
- every time-step host gets updated property's of shapes , sends them clients (x, y, rotation, sleep)
- the client applys shape property's correct shapes
i tried different time-steps , noticed until time-step of 1/15 second client(slave) won't notice lagging in game. tried pick lower time-step , tween movement of shapes did give strange movement on client(slave) side.
i give example of single object update packet.
<o|t=s:u|x=201|y=202|f=automaticoo</o <o|t=m:p|x=100|y=345|f=automaticoo</o
i noticed flash player can stack lot of packets in buffer before sending. example if send lot of packets @ once stacks them , send them server. faster time-steps don't more updates on client(slave) side more updates in same packet row.
tries
- use new rtmfp(udp & p2p) protocol updates. (little bit better in performance less in reliability)
- code entire socket server in c++ instead of air(with serversocket) (better in performance noticed lagging part not server flash player)
- use bytearray compress method , amf serialized format (performance same except c++ server can't unserialize messages)
do guys think possible in flash player handle many update request each time-step.
discoveries
there stick arena game multiplayer in actionscript 3.0. used lot of tricking , ping of 300ms , updates players (4 players in lobby).
sorry long post.
i believe problem comes down type of game , data.
this again broken into:
- server speed (calculations need in cpu + ram requirements world/player data)
- connection speed (bandwidth on server)
- data size (how info needed , how often)
- player interaction form (event or fps)
- distance client server (ping)
mmorg
eg. world of warcraft, knowledge on none-pvp worlds using "client viewport" , "client sends keystrokes", "server validates , performs, , tells client happens" on client-server base.
this gives game lot of acceptable latency need transfer commands client , results client. rest drawn on client.
its event driven , click icon or press key, okay "spell" needs time fire on server. secondly there no player collision needed. lets server process less data , keeps requirements server cpu smaller.
counter-strike / battlefield etc.
fps, fast paced action, quick response needs information every detail time. makes higher demand on precision. collision must both player , weapons.
this sort of game doesnt handle more 32 players on single map, need able share positions, bullets, explosions etc. fast , data has go through server-validation again bottleneck type of online game.
network latency
in perfect world 0 ms, know. hardware client server , takes time. both going through network stacks , through internet connection (switch, router, modem, fiber centrals etc) way many modern real time games fixes "prediction". let server @ direction , speed. try predict (much gps in tunnel too) last seen moving forward speed of +4 given timeframe have moved (timeframes x 4) - if had slowed down or speeded up? either instantly "hyperjump" b in split second , feel lagging game or easy real position "hero" slides little faster or slower right possition.
this technique explained many places on net, no need details in here, takes time , tweaks performance - works , saves lot of headaches programmers.
what network data needed?
i read question , thought: compressed quite lot. secondly, have made flash socket chat pure bytestream , worked awesome. hard running start, once got , running fast.
the flash client/player isnt biggest networking client, expect lot of lost speed there too. go 10-15 fps networking part , use more raw approach data sent , forth.
lastly, try keep data simple possible.
eg. use commands/shortcuts data/events. server data bytestring be: 0x99, 0x45,0x75,0x14,0x04,0x06
where 0x99 means : big explosion @ following coords: (0x45,0x75) 0x14 means: player 0x14 (player 20 in decimal) has moved (0x04, 0x06)
so staring opcode tells networking protocol handler in client , server expect next. (its how cpu knows how read memory btw.)
for chat had commands each type of data parsed. 1 login, 1 broadcasting, for telling name of user etc. once client made login, client received command + packed of online users. transfed once client. after each attached client received "new user online" command name of new user. each client maintained own list current users , id's needed tell client number text. kept traffic @ minimum. same go coordinates or commands of do. "player #20 goes north" etc. be 0x14, 0x41, 0xf0 (0x41 move, 0xf0 north, 0xf1 east etc.)
this physical distance game
this 1 cant change, can put in restrictions or make servers run in multiple locations worldwide, depending on type of game wanna make. amazon ec2 great platform such projects have data-centers on world , can benchmark users network against these , redirect users nearest datacenter running server.
hacking/cheating
also remember, if gets popular , start earning money on it, sooner or later try break protocols or break down accounts gain access servers, informations or cheat further items/points in games. attacked ddos bomb network wrong data crash , render game unusable.
dont mind start, remember once go online, never know in world or in world are. i'm not trying make paranoid, there sick people try earn money cheating others.
so think structures, dont show data in network packages isnt needed. dont believe data client correct. validate data on server-side.
this takes time if have 100 active players @ same time.
but once it, can sleep better if gets big success you, hope.
that thoughts experience. hope of might usefull eventhough didnt quite answer if 100 players possible.
infact say: yes 100 players possible, depends if move @ same time , there collission testing involved , if accept lag or not.
Comments
Post a Comment