Commit 41570fe6 by Nick An

fix doc

parent c04468c7
...@@ -16,7 +16,7 @@ module CrazyFlirt ...@@ -16,7 +16,7 @@ module CrazyFlirt
5.times do 5.times do
random_key += words[random.rand(0..size)] random_key += words[random.rand(0..size)]
end end
Time.now.to_s.to_i.to_s + random_key Time.now.to_i.to_s + random_key
end end
end end
...@@ -81,13 +81,16 @@ module CrazyFlirt ...@@ -81,13 +81,16 @@ module CrazyFlirt
@clients = [] @clients = []
@name = name @name = name
@status = :waiting @status = :waiting
@mutex = Mutex.new
end end
def set_client(client) def set_client(client)
return unless @status == :waiting return unless @status == :waiting
@mutex.synchronize do
@clients << client @clients << client
@clients.size - 1 @clients.size - 1
end end
end
def start! def start!
@status = :start @status = :start
...@@ -117,6 +120,7 @@ module CrazyFlirt ...@@ -117,6 +120,7 @@ module CrazyFlirt
ws = @faye.new(env) ws = @faye.new(env)
client = ::CrazyFlirt::Client.new(ws) client = ::CrazyFlirt::Client.new(ws)
@socket_pool[client.key] = client @socket_pool[client.key] = client
ws.on :message do |event| ws.on :message do |event|
message = JSON.parse(event.data) message = JSON.parse(event.data)
seq = message['type'] seq = message['type']
...@@ -128,11 +132,16 @@ module CrazyFlirt ...@@ -128,11 +132,16 @@ module CrazyFlirt
ws.on :close do |event| ws.on :close do |event|
puts "leave key #{client.key}" puts "leave key #{client.key}"
@socket_pool.delete(client.key) @socket_pool.delete(client.key)
p client.room p client.room.nil?
client.room.leave_client(client.key) client.room.leave_client(client.key) unless client.room.nil?
client = nil client = nil
puts 'closed' puts 'closed'
end end
ws.on(:error) do |event|
puts event.code
ws.close()
end
ws.rack_response ws.rack_response
end end
...@@ -160,7 +169,7 @@ module CrazyFlirt ...@@ -160,7 +169,7 @@ module CrazyFlirt
puts 'notice' puts 'notice'
notice_all(room, { notice_all(room, {
type: 'game_end', type: 'game_end',
room_id: room.name, rid: room.name,
payload:{ payload:{
} }
}) })
...@@ -171,7 +180,7 @@ module CrazyFlirt ...@@ -171,7 +180,7 @@ module CrazyFlirt
x,y = RandomPicker.item_generate x,y = RandomPicker.item_generate
notice_all(room,{ notice_all(room,{
type: 'item_refresh', type: 'item_refresh',
room_id: 'default_room', rid: 'default_room',
payload:{ payload:{
x:x, x:x,
y:y y:y
...@@ -208,11 +217,11 @@ module CrazyFlirt ...@@ -208,11 +217,11 @@ module CrazyFlirt
def ready_message(room, client) def ready_message(room, client)
{ {
type: 'game_ready', type: 'game_ready',
cid: client.id, cid: client.key,
room_id: room.name, rid: room.name,
payload: { payload: {
open_id: client.open_id, nick_name: client.user_info['nick_name'],
picture: client.picture, avatar_url: client.user_info['avatar_url'],
} }
} }
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment