Skip to content

Instantly share code, notes, and snippets.

@marcgg
Last active November 20, 2016 14:27
Show Gist options
  • Save marcgg/47233a6ca0fe8cc126685bc2a635460c to your computer and use it in GitHub Desktop.
Save marcgg/47233a6ca0fe8cc126685bc2a635460c to your computer and use it in GitHub Desktop.
class Note
def self.add(player_id, x, y)
key = "note_#{SecureRandom.hex}"
REDIS.set(key, {
x: x, y: y, player_id: player_id
}.to_json)
REDIS.expire(key, 5)
broadcast_note(player_id, x, y)
REDIS.incr("count_notes")
end
private
def self.broadcast_note(player_id, x, y)
puts "Broadcasting note by #{player_id}"
ActionCable.server.broadcast(
"game", {
type: "note",
player_id: player_id,
x: x, y: y
}
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment