Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
crazyflirt
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shawn Wang
crazyflirt
Commits
41570fe6
Commit
41570fe6
authored
May 05, 2018
by
Nick An
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix doc
parent
c04468c7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
9 deletions
+18
-9
index.rb
be/index.rb
+18
-9
No files found.
be/index.rb
View file @
41570fe6
...
...
@@ -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'
,
r
oom_
id:
room
.
name
,
rid:
room
.
name
,
payload
:{
}
})
...
...
@@ -171,7 +180,7 @@ module CrazyFlirt
x
,
y
=
RandomPicker
.
item_generate
notice_all
(
room
,{
type:
'item_refresh'
,
r
oom_
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
,
r
oom_
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment