Jump to content

Phaser admit hit in multiplayer


Hadik
 Share

Recommended Posts

Hello, I cant find any good solution how admit hit between two players in nodejs (with socketio) with phaser.

 

There is some solution, with problems.

 

1. Player A create bullet and send to server X,Y,rotation (speed will be constant), server send create event to other clients and create ghost bullet. When will hit this bullet to same player, player get damage (its local event, because bullet is created in his game, and collision detect  call damage to player)

 

This solution is very good, but there is very big problem. When target player minimalize game, or switch tab, socketio, and mainly javascript thread will be paused and this player/client cant admin, get hit, becuase. Server send create bullet event, but this client is "paused" and not create bullet and not get hit. How I can solve this ? Because, it will be easy cheat for god mode.

 

 

2. Hit solve on attacker side (player who will fire), just when his bullet hit someone, it send to everybody. I hit player XXX, and every client will recieve this hit and localy get this ghost player/dummy damage, after will be zero, just destroy/hide it. This solution will not be depenes on paused javascript thread.

 

This solution is hard to create and mainly, create some cheat will be very easy (just send concrete socket with target player)

 

 

So I want to use first solution, but how I can avoid puase to main thread (also in mobile phone, user just close browser, but game will run on background - yes I can use some kind of hearbeat and kick this user) But when player just switch to messenger reply friends, go back to game, and will be kicked ?

 

Thanks for every good solution :)

 

 

Link to comment
Share on other sites

You should use number 1, however it's only half implemented... you should never allow the client to do anything important... like a local event that would deal the damage.. The way I combatted this, is the bullet class, or arrow class in my case.. would make a callback to the network manager. This would tell the server 'i'm a bullet, I was shot from player x, and I hit player y'. The server can then tell everybody the news. The reason this is done like this, is because if the client can tell the server when you hit, you are opening yourself up for some massive easy hacking potential. Another reason for using this solution is you can check the positions of all the relative players and bullets. If the server smells something fishy going on, then it can destroy the bullet, kick the player etc...

Also, you can use this.game.stage.disableVisibilityChange = true; as a way of keeping the game logic running, even when the tab is changed and the canvas has lost focus.

 

Link to comment
Share on other sites

Haha, this is the exact same issue I had:

I asked if the creator of NW.js could implement this feature since it's a Chromium issue.

https://groups.google.com/d/msg/nwjs-general/KiSR4vWOUnw/8UQYT_KsCgAJ

You can enable this by adding "chromium-args" : "--disable-raf-throttling", inside your package.json. (This also means, you must use NW.js for your game since the official Chromium doesn't support this yet, e.g: Chrome)

And for electron, they are still working on it: That pull request is here: https://github.com/electron/electron/pull/5086

But, it's also very important to use this.game.stage.disableVisibilityChange = true  (as @megmut said). This is because RAF actually get's disabled when the browser becomes unfocused IIRC too. So using disableVisibilityChange with the --disable-raf-throttling argument will make your game run 100%  regardless of being minimized / unfocused. This is essential for multiplayer games. For example, if you are playing treasureArena, and minimize the browser and come back in 20 seconds, the game is pooped. 

The NW.js raf throttling feature also disables the throttling of timers in the background as well (setInterval, setTimeout, etc). So that is nice, and Electron has a chromium argument to disable timer throttling, but last time I checked it's not working. In any event, using NW.js for now would be your fix and maybe you can switch to electron later dependent on which one you like more. Both are great.

 

Regards to your multiplayer setup. It depends. Do you want to run arcade physics on the server or just rely on client-side physics that then communicate with the server on collisions?  Obviously, running server-side physics would be the safest way, but there is a trade off of performance and scale-ability.  Having a basic server-side cool-down and a range check  will prevent most exploiting.. The worst thing a hacker could do is shoot a fireball. and then not use their wrist to point it in the right direction. :P

But, for PVP, I wouldn't do it like that. I'd recommend some type of server-side collision 

Edit: This is all assuming you are using AABB  physics (arcade)

Link to comment
Share on other sites

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...