Commit 41570fe6 by Nick An

fix doc

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