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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
11 deletions
+20
-11
index.rb
be/index.rb
+20
-11
No files found.
be/index.rb
View file @
41570fe6
...
@@ -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,12 +81,15 @@ module CrazyFlirt
...
@@ -81,12 +81,15 @@ 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
@clients
<<
client
@mutex
.
synchronize
do
@clients
.
size
-
1
@clients
<<
client
@clients
.
size
-
1
end
end
end
def
start!
def
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'
,
r
oom_
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'
,
r
oom_
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
,
r
oom_
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
...
...
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