Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
srvpro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
srvpro
Commits
39ee483e
Commit
39ee483e
authored
Sep 29, 2015
by
mercury233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add
parent
5a2989b7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
21 deletions
+88
-21
room.coffee
room.coffee
+29
-2
room.js
room.js
+39
-1
ygopro-server.coffee
ygopro-server.coffee
+13
-10
ygopro-server.js
ygopro-server.js
+7
-8
No files found.
room.coffee
View file @
39ee483e
...
@@ -31,20 +31,42 @@ class Room
...
@@ -31,20 +31,42 @@ class Room
#alive
#alive
@
all
=
[]
@
all
=
[]
@
players_oppentlist
=
{}
@
find_or_create_by_name
:
(
name
)
->
@
find_or_create_by_name
:
(
name
,
player_name
)
->
if
name
==
''
or
name
.
toUpperCase
()
==
'S'
or
name
.
toUpperCase
()
==
'M'
return
@
find_or_create_random
(
name
.
toUpperCase
(),
player_name
)
if
room
=
@
find_by_name
(
name
)
if
room
=
@
find_by_name
(
name
)
return
room
return
room
else
if
get_memory_usage
()
>=
90
else
if
get_memory_usage
()
>=
90
return
null
return
null
else
else
return
new
Room
(
name
)
return
new
Room
(
name
)
@
find_or_create_random
:
(
type
,
player_name
)
->
if
type
==
''
result
=
_
.
find
@
all
,
(
room
)
->
room
.
random_type
and
room
.
players
.
length
==
1
and
room
.
players
[
0
].
name
!=
Room
.
players_oppentlist
[
player_name
]
else
result
=
_
.
find
@
all
,
(
room
)
->
room
.
random_type
==
type
and
room
.
players
.
length
==
1
and
room
.
players
[
0
].
name
!=
Room
.
players_oppentlist
[
player_name
]
if
result
result
.
welcome
=
'对手已经在等你了,开始决斗吧!'
log
.
info
'found room'
,
player_name
else
type
=
if
type
then
type
else
'S'
name
=
type
+
',RANDOM#'
+
Math
.
floor
(
Math
.
random
()
*
100000
)
result
=
new
Room
(
name
)
result
.
random_type
=
type
result
.
welcome
=
'已建立随机对战房间,正在等待对手!'
log
.
info
'create room'
,
player_name
,
name
return
result
@
find_by_name
:
(
name
)
->
@
find_by_name
:
(
name
)
->
result
=
_
.
find
@
all
,
(
room
)
->
result
=
_
.
find
@
all
,
(
room
)
->
room
.
name
==
name
room
.
name
==
name
#log.info 'find_by_name', name, result
#log.info 'find_by_name', name, result
result
re
turn
re
sult
@
find_by_port
:
(
port
)
->
@
find_by_port
:
(
port
)
->
_
.
find
@
all
,
(
room
)
->
_
.
find
@
all
,
(
room
)
->
...
@@ -68,6 +90,8 @@ class Room
...
@@ -68,6 +90,8 @@ class Room
@
established
=
false
@
established
=
false
@
watcher_buffers
=
[]
@
watcher_buffers
=
[]
@
watchers
=
[]
@
watchers
=
[]
@
random_type
=
''
@
welcome
=
''
Room
.
all
.
push
this
Room
.
all
.
push
this
@
hostinfo
=
@
hostinfo
=
...
@@ -250,6 +274,9 @@ class Room
...
@@ -250,6 +274,9 @@ class Room
connect
:
(
client
)
->
connect
:
(
client
)
->
@
players
.
push
client
@
players
.
push
client
if
@
random_type
Room
.
players_oppentlist
[
@
players
[
0
].
name
]
=
if
@
players
[
1
]
then
@
players
[
1
].
name
else
null
if
@
players
[
1
]
then
Room
.
players_oppentlist
[
@
players
[
1
].
name
]
=
@
players
[
0
].
name
if
@
established
if
@
established
client
.
server
.
connect
@
port
,
'127.0.0.1'
,
->
client
.
server
.
connect
@
port
,
'127.0.0.1'
,
->
...
...
room.js
View file @
39ee483e
...
@@ -39,8 +39,13 @@
...
@@ -39,8 +39,13 @@
Room
=
(
function
()
{
Room
=
(
function
()
{
Room
.
all
=
[];
Room
.
all
=
[];
Room
.
find_or_create_by_name
=
function
(
name
)
{
Room
.
players_oppentlist
=
{};
Room
.
find_or_create_by_name
=
function
(
name
,
player_name
)
{
var
room
;
var
room
;
if
(
name
===
''
||
name
.
toUpperCase
()
===
'
S
'
||
name
.
toUpperCase
()
===
'
M
'
)
{
return
this
.
find_or_create_random
(
name
.
toUpperCase
(),
player_name
);
}
if
(
room
=
this
.
find_by_name
(
name
))
{
if
(
room
=
this
.
find_by_name
(
name
))
{
return
room
;
return
room
;
}
else
if
(
get_memory_usage
()
>=
90
)
{
}
else
if
(
get_memory_usage
()
>=
90
)
{
...
@@ -50,6 +55,31 @@
...
@@ -50,6 +55,31 @@
}
}
};
};
Room
.
find_or_create_random
=
function
(
type
,
player_name
)
{
var
name
,
result
;
if
(
type
===
''
)
{
result
=
_
.
find
(
this
.
all
,
function
(
room
)
{
return
room
.
random_type
&&
room
.
players
.
length
===
1
&&
room
.
players
[
0
].
name
!==
Room
.
players_oppentlist
[
player_name
];
});
}
else
{
result
=
_
.
find
(
this
.
all
,
function
(
room
)
{
return
room
.
random_type
===
type
&&
room
.
players
.
length
===
1
&&
room
.
players
[
0
].
name
!==
Room
.
players_oppentlist
[
player_name
];
});
}
if
(
result
)
{
result
.
welcome
=
'
对手已经在等你了,开始决斗吧!
'
;
log
.
info
(
'
found room
'
,
player_name
);
}
else
{
type
=
type
?
type
:
'
S
'
;
name
=
type
+
'
,RANDOM#
'
+
Math
.
floor
(
Math
.
random
()
*
100000
);
result
=
new
Room
(
name
);
result
.
random_type
=
type
;
result
.
welcome
=
'
已建立随机对战房间,正在等待对手!
'
;
log
.
info
(
'
create room
'
,
player_name
,
name
);
}
return
result
;
};
Room
.
find_by_name
=
function
(
name
)
{
Room
.
find_by_name
=
function
(
name
)
{
var
result
;
var
result
;
result
=
_
.
find
(
this
.
all
,
function
(
room
)
{
result
=
_
.
find
(
this
.
all
,
function
(
room
)
{
...
@@ -87,6 +117,8 @@
...
@@ -87,6 +117,8 @@
this
.
established
=
false
;
this
.
established
=
false
;
this
.
watcher_buffers
=
[];
this
.
watcher_buffers
=
[];
this
.
watchers
=
[];
this
.
watchers
=
[];
this
.
random_type
=
''
;
this
.
welcome
=
''
;
Room
.
all
.
push
(
this
);
Room
.
all
.
push
(
this
);
this
.
hostinfo
=
{
this
.
hostinfo
=
{
lflist
:
0
,
lflist
:
0
,
...
@@ -313,6 +345,12 @@
...
@@ -313,6 +345,12 @@
Room
.
prototype
.
connect
=
function
(
client
)
{
Room
.
prototype
.
connect
=
function
(
client
)
{
this
.
players
.
push
(
client
);
this
.
players
.
push
(
client
);
if
(
this
.
random_type
)
{
Room
.
players_oppentlist
[
this
.
players
[
0
].
name
]
=
this
.
players
[
1
]
?
this
.
players
[
1
].
name
:
null
;
if
(
this
.
players
[
1
])
{
Room
.
players_oppentlist
[
this
.
players
[
1
].
name
]
=
this
.
players
[
0
].
name
;
}
}
if
(
this
.
established
)
{
if
(
this
.
established
)
{
client
.
server
.
connect
(
this
.
port
,
'
127.0.0.1
'
,
function
()
{
client
.
server
.
connect
(
this
.
port
,
'
127.0.0.1
'
,
function
()
{
var
buffer
,
i
,
len
,
ref
;
var
buffer
,
i
,
len
,
ref
;
...
...
ygopro-server.coffee
View file @
39ee483e
...
@@ -228,13 +228,13 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
...
@@ -228,13 +228,13 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
}
}
client
.
end
()
client
.
end
()
else
if
!
info
.
pass
.
length
#
else if !info.pass.length
ygopro
.
stoc_send_chat
(
client
,
"房间为空,请修改房间名"
)
#
ygopro.stoc_send_chat(client,"房间为空,请修改房间名")
ygopro
.
stoc_send
client
,
'ERROR_MSG'
,{
#
ygopro.stoc_send client, 'ERROR_MSG',{
msg
:
1
#
msg: 1
code
:
2
#
code: 2
}
#
}
client
.
end
()
#
client.end()
else
if
!
Room
.
validate
(
info
.
pass
)
else
if
!
Room
.
validate
(
info
.
pass
)
#ygopro.stoc_send client, 'ERROR_MSG',{
#ygopro.stoc_send client, 'ERROR_MSG',{
...
@@ -257,7 +257,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
...
@@ -257,7 +257,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
else
else
#log.info 'join_game',info.pass, client.name
#log.info 'join_game',info.pass, client.name
client
.
room
=
Room
.
find_or_create_by_name
(
info
.
pass
)
client
.
room
=
Room
.
find_or_create_by_name
(
info
.
pass
,
client
.
name
)
if
!
client
.
room
if
!
client
.
room
ygopro
.
stoc_send_chat
(
client
,
"服务器已经爆满,请稍候再试"
)
ygopro
.
stoc_send_chat
(
client
,
"服务器已经爆满,请稍候再试"
)
ygopro
.
stoc_send
client
,
'ERROR_MSG'
,{
ygopro
.
stoc_send
client
,
'ERROR_MSG'
,{
...
@@ -289,8 +289,8 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)->
...
@@ -289,8 +289,8 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)->
return
unless
client
.
room
return
unless
client
.
room
if
settings
.
modules
.
welcome
if
settings
.
modules
.
welcome
ygopro
.
stoc_send_chat
client
,
settings
.
modules
.
welcome
ygopro
.
stoc_send_chat
client
,
settings
.
modules
.
welcome
##if (os.freemem() / os.totalmem())<=0.1
if
client
.
room
.
welcome
## ygopro.stoc_send_chat client, "服务器已经爆满,随时存在崩溃风险!"
ygopro
.
stoc_send_chat
client
,
client
.
room
.
welcome
if
settings
.
modules
.
post_start_watching
and
!
client
.
room
.
watcher
if
settings
.
modules
.
post_start_watching
and
!
client
.
room
.
watcher
client
.
room
.
watcher
=
watcher
=
net
.
connect
client
.
room
.
port
,
->
client
.
room
.
watcher
=
watcher
=
net
.
connect
client
.
room
.
port
,
->
...
@@ -449,6 +449,9 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server)->
...
@@ -449,6 +449,9 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server)->
when
'/tip'
when
'/tip'
ygopro
.
stoc_send_random_tip
(
client
)
if
settings
.
modules
.
tips
ygopro
.
stoc_send_random_tip
(
client
)
if
settings
.
modules
.
tips
when
'/test'
log
.
info
Room
.
players_oppentlist
return
cancel
return
cancel
ygopro
.
ctos_follow
'UPDATE_DECK'
,
false
,
(
buffer
,
info
,
client
,
server
)
->
ygopro
.
ctos_follow
'UPDATE_DECK'
,
false
,
(
buffer
,
info
,
client
,
server
)
->
...
...
ygopro-server.js
View file @
39ee483e
...
@@ -256,13 +256,6 @@
...
@@ -256,13 +256,6 @@
code
:
settings
.
version
code
:
settings
.
version
});
});
client
.
end
();
client
.
end
();
}
else
if
(
!
info
.
pass
.
length
)
{
ygopro
.
stoc_send_chat
(
client
,
"
房间为空,请修改房间名
"
);
ygopro
.
stoc_send
(
client
,
'
ERROR_MSG
'
,
{
msg
:
1
,
code
:
2
});
client
.
end
();
}
else
if
(
!
Room
.
validate
(
info
.
pass
))
{
}
else
if
(
!
Room
.
validate
(
info
.
pass
))
{
ygopro
.
stoc_send_chat
(
client
,
"
房间密码不正确
"
);
ygopro
.
stoc_send_chat
(
client
,
"
房间密码不正确
"
);
ygopro
.
stoc_send
(
client
,
'
ERROR_MSG
'
,
{
ygopro
.
stoc_send
(
client
,
'
ERROR_MSG
'
,
{
...
@@ -277,7 +270,7 @@
...
@@ -277,7 +270,7 @@
});
});
client
.
end
();
client
.
end
();
}
else
{
}
else
{
client
.
room
=
Room
.
find_or_create_by_name
(
info
.
pass
);
client
.
room
=
Room
.
find_or_create_by_name
(
info
.
pass
,
client
.
name
);
if
(
!
client
.
room
)
{
if
(
!
client
.
room
)
{
ygopro
.
stoc_send_chat
(
client
,
"
服务器已经爆满,请稍候再试
"
);
ygopro
.
stoc_send_chat
(
client
,
"
服务器已经爆满,请稍候再试
"
);
ygopro
.
stoc_send
(
client
,
'
ERROR_MSG
'
,
{
ygopro
.
stoc_send
(
client
,
'
ERROR_MSG
'
,
{
...
@@ -318,6 +311,9 @@
...
@@ -318,6 +311,9 @@
if
(
settings
.
modules
.
welcome
)
{
if
(
settings
.
modules
.
welcome
)
{
ygopro
.
stoc_send_chat
(
client
,
settings
.
modules
.
welcome
);
ygopro
.
stoc_send_chat
(
client
,
settings
.
modules
.
welcome
);
}
}
if
(
client
.
room
.
welcome
)
{
ygopro
.
stoc_send_chat
(
client
,
client
.
room
.
welcome
);
}
if
(
settings
.
modules
.
post_start_watching
&&
!
client
.
room
.
watcher
)
{
if
(
settings
.
modules
.
post_start_watching
&&
!
client
.
room
.
watcher
)
{
client
.
room
.
watcher
=
watcher
=
net
.
connect
(
client
.
room
.
port
,
function
()
{
client
.
room
.
watcher
=
watcher
=
net
.
connect
(
client
.
room
.
port
,
function
()
{
ygopro
.
ctos_send
(
watcher
,
'
PLAYER_INFO
'
,
{
ygopro
.
ctos_send
(
watcher
,
'
PLAYER_INFO
'
,
{
...
@@ -510,6 +506,9 @@
...
@@ -510,6 +506,9 @@
if
(
settings
.
modules
.
tips
)
{
if
(
settings
.
modules
.
tips
)
{
ygopro
.
stoc_send_random_tip
(
client
);
ygopro
.
stoc_send_random_tip
(
client
);
}
}
break
;
case
'
/test
'
:
log
.
info
(
Room
.
players_oppentlist
);
}
}
return
cancel
;
return
cancel
;
});
});
...
...
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