问题描述:

I am working on a multiplayer android app and trying to implement a part of the game which a player can attack to a nearby player. I have decided to use socket io for that purpose.

This is what I have already implemented:

Client:

  • socket.connect

    • socket.emit("connectData", playerId)
  • if player attacks to nearby player

    • socket.emit("attack", nearbyPlayerId)
  • listening attack response event
  • listening damage event

Server:

  • hashmap to keep track of connected players: playersMap
  • on player connected

    • playersMap.put(playerId, socket)
    • on player attacked

      • socket.emit("attackResponse", data)
      • nearbyPlayerSocket = playersMap.get(nearbyPlayerId)
      • nearbyPlayerSocket.emit("damage", data)

However, if someone finds a way to connect the socket io server (which is possible with just using a connection url), they can emit "attack" event with a player id data (without using android application). How can I detect that from a server side? Maybe I can create a session on the server when a player login from the android application and allow the player to emit event through that session, but I do not know how I can do that.

相关阅读:
Top