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
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
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
nanahira
srvpro
Commits
fd0ca6d7
Commit
fd0ca6d7
authored
Aug 11, 2016
by
mercury233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update add windbot
parent
90ec4082
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
135 additions
and
88 deletions
+135
-88
config.json
config.json
+1
-0
ygopro-server.coffee
ygopro-server.coffee
+57
-41
ygopro-server.js
ygopro-server.js
+77
-47
No files found.
config.json
View file @
fd0ca6d7
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
"enable_windbot"
:
false
,
"enable_windbot"
:
false
,
"enable_websocket_roomlist"
:
false
,
"enable_websocket_roomlist"
:
false
,
"redis_port"
:
6379
,
"redis_port"
:
6379
,
"windbot_port"
:
2399
,
"mycard_auth"
:
false
,
"mycard_auth"
:
false
,
"mycard_auth_key"
:
"please set in config.user.json"
,
"mycard_auth_key"
:
"please set in config.user.json"
,
"hang_timeout"
:
90
,
"hang_timeout"
:
90
,
...
...
ygopro-server.coffee
View file @
fd0ca6d7
...
@@ -161,8 +161,11 @@ ROOM_ban_player = (name, ip, reason, countadd = 1)->
...
@@ -161,8 +161,11 @@ ROOM_ban_player = (name, ip, reason, countadd = 1)->
return
return
ROOM_find_or_create_by_name
=
(
name
,
player_ip
)
->
ROOM_find_or_create_by_name
=
(
name
,
player_ip
)
->
if
settings
.
modules
.
enable_random_duel
and
(
name
==
''
or
name
.
toUpperCase
()
==
'S'
or
name
.
toUpperCase
()
==
'M'
or
name
.
toUpperCase
()
==
'T'
)
uname
=
name
.
toUpperCase
()
return
ROOM_find_or_create_random
(
name
.
toUpperCase
(),
player_ip
)
if
settings
.
modules
.
enable_windbot
and
(
uname
[
0
...
2
]
==
'AI'
or
(
!
settings
.
modules
.
enable_random_duel
and
uname
==
''
))
return
ROOM_find_or_create_ai
(
name
)
if
settings
.
modules
.
enable_random_duel
and
(
uname
==
''
or
uname
==
'S'
or
uname
==
'M'
or
uname
==
'T'
)
return
ROOM_find_or_create_random
(
uname
,
player_ip
)
if
room
=
ROOM_find_by_name
(
name
)
if
room
=
ROOM_find_by_name
(
name
)
return
room
return
room
else
if
get_memory_usage
()
>=
90
else
if
get_memory_usage
()
>=
90
...
@@ -195,7 +198,7 @@ ROOM_find_or_create_random = (type, player_ip)->
...
@@ -195,7 +198,7 @@ ROOM_find_or_create_random = (type, player_ip)->
if
result
if
result
result
.
welcome
=
'对手已经在等你了,开始决斗吧!'
result
.
welcome
=
'对手已经在等你了,开始决斗吧!'
#log.info 'found room', player_name
#log.info 'found room', player_name
else
else
if
get_memory_usage
()
<
90
type
=
if
type
then
type
else
'S'
type
=
if
type
then
type
else
'S'
name
=
type
+
',RANDOM#'
+
Math
.
floor
(
Math
.
random
()
*
100000
)
name
=
type
+
',RANDOM#'
+
Math
.
floor
(
Math
.
random
()
*
100000
)
result
=
new
Room
(
name
)
result
=
new
Room
(
name
)
...
@@ -204,9 +207,35 @@ ROOM_find_or_create_random = (type, player_ip)->
...
@@ -204,9 +207,35 @@ ROOM_find_or_create_random = (type, player_ip)->
result
.
welcome
=
'已建立随机对战房间,正在等待对手!'
result
.
welcome
=
'已建立随机对战房间,正在等待对手!'
result
.
deprecated
=
playerbanned
result
.
deprecated
=
playerbanned
#log.info 'create room', player_name, name
#log.info 'create room', player_name, name
else
return
null
if
result
.
random_type
==
'M'
then
result
.
welcome
=
result
.
welcome
+
'
\n
您进入了比赛模式的房间,我们推荐使用竞技卡组!'
if
result
.
random_type
==
'M'
then
result
.
welcome
=
result
.
welcome
+
'
\n
您进入了比赛模式的房间,我们推荐使用竞技卡组!'
return
result
return
result
ROOM_find_or_create_ai
=
(
name
)
->
if
name
==
''
name
=
'AI'
if
name
[
0
...
3
]
==
'AI_'
name
=
'AI#'
+
name
.
slice
(
3
)
if
room
=
ROOM_find_by_name
(
name
)
return
room
else
if
name
==
'AI'
windbot
=
_
.
sample
settings
.
modules
.
windbots
name
=
'AI#'
+
Math
.
floor
(
Math
.
random
()
*
100000
)
else
if
ainame
=
name
.
split
(
'#'
)[
1
]
windbot
=
_
.
sample
_
.
filter
settings
.
modules
.
windbots
,
(
w
)
->
w
.
name
==
ainame
or
w
.
deck
==
ainame
if
!
windbot
return
{
"error"
:
"未找到该AI角色或卡组"
}
name
=
name
+
','
+
Math
.
floor
(
Math
.
random
()
*
100000
)
else
windbot
=
_
.
sample
settings
.
modules
.
windbots
name
=
name
+
'#'
+
Math
.
floor
(
Math
.
random
()
*
100000
)
result
=
new
Room
(
name
)
result
.
windbot
=
windbot
return
result
ROOM_find_by_name
=
(
name
)
->
ROOM_find_by_name
=
(
name
)
->
result
=
_
.
find
ROOM_all
,
(
room
)
->
result
=
_
.
find
ROOM_all
,
(
room
)
->
return
room
and
room
.
name
==
name
return
room
and
room
.
name
==
name
...
@@ -419,7 +448,9 @@ class Room
...
@@ -419,7 +448,9 @@ class Room
return
return
return
return
if
@
windbot
if
@
windbot
request
.
get
"http://127.0.0.1:2399/?name=
#{
encodeURIComponent
(
@
windbot
.
name
)
}
&deck=
#{
encodeURIComponent
(
@
windbot
.
deck
)
}
&host=127.0.0.1&port=
#{
@
port
}
&dialog=
#{
encodeURIComponent
(
@
windbot
.
dialog
)
}
&version=
#{
settings
.
version
}
"
setTimeout
()
=>
@
add_windbot
(
@
windbot
)
,
200
return
return
@
process
.
stderr
.
on
'data'
,
(
data
)
=>
@
process
.
stderr
.
on
'data'
,
(
data
)
=>
data
=
"Debug: "
+
data
data
=
"Debug: "
+
data
...
@@ -492,6 +523,19 @@ class Room
...
@@ -492,6 +523,19 @@ class Room
return
return
return
host_player
return
host_player
add_windbot
:
(
botdata
)
->
@
windbot
=
botdata
request
url
:
"http://127.0.0.1:
#{
settings
.
modules
.
windbot_port
}
/?name=
#{
encodeURIComponent
(
botdata
.
name
)
}
&deck=
#{
encodeURIComponent
(
botdata
.
deck
)
}
&host=127.0.0.1&port=
#{
settings
.
port
}
&dialog=
#{
encodeURIComponent
(
botdata
.
dialog
)
}
&version=
#{
settings
.
version
}
&password=
#{
encodeURIComponent
(
@
name
)
}
"
,
(
error
,
response
,
body
)
=>
if
error
log
.
warn
'windbot add error'
,
error
,
this
.
name
,
response
ygopro
.
stoc_send_chat_to_room
(
this
,
"添加AI失败,可尝试输入 /ai 重新添加"
,
ygopro
.
constants
.
COLORS
.
RED
)
else
log
.
info
"windbot added"
return
return
connect
:
(
client
)
->
connect
:
(
client
)
->
@
players
.
push
client
@
players
.
push
client
client
.
ip
=
client
.
remoteAddress
client
.
ip
=
client
.
remoteAddress
...
@@ -527,7 +571,7 @@ class Room
...
@@ -527,7 +571,7 @@ class Room
#log.info(@started,@disconnector,@random_type)
#log.info(@started,@disconnector,@random_type)
if
@
started
and
@
disconnector
!=
'server'
and
@
random_type
if
@
started
and
@
disconnector
!=
'server'
and
@
random_type
ROOM_ban_player
(
client
.
name
,
client
.
ip
,
"强退"
)
ROOM_ban_player
(
client
.
name
,
client
.
ip
,
"强退"
)
if
@
players
.
length
if
@
players
.
length
and
!
(
@
windbot
and
client
.
is_host
)
ygopro
.
stoc_send_chat_to_room
this
,
"
#{
client
.
name
}
离开了游戏"
+
if
error
then
":
#{
error
}
"
else
''
ygopro
.
stoc_send_chat_to_room
this
,
"
#{
client
.
name
}
离开了游戏"
+
if
error
then
":
#{
error
}
"
else
''
roomlist
.
update
(
this
)
if
!
@
private
and
!
@
started
and
settings
.
modules
.
enable_websocket_roomlist
roomlist
.
update
(
this
)
if
!
@
private
and
!
@
started
and
settings
.
modules
.
enable_websocket_roomlist
#client.room = null
#client.room = null
...
@@ -807,42 +851,10 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
...
@@ -807,42 +851,10 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
}
}
client
.
end
()
client
.
end
()
else
if
!
info
.
pass
.
length
and
!
settings
.
modules
.
enable_random_duel
else
if
!
info
.
pass
.
length
and
!
settings
.
modules
.
enable_random_duel
and
!
settings
.
modules
.
enable_windbot
ygopro
.
stoc_die
(
client
,
"房间名为空,请填写主机密码"
)
ygopro
.
stoc_die
(
client
,
"房间名为空,请填写主机密码"
)
else
if
settings
.
modules
.
enable_windbot
and
info
.
pass
[
0
...
2
]
==
'AI'
else
if
info
.
pass
.
length
and
settings
.
modules
.
mycard_auth
and
info
.
pass
[
0
...
2
]
!=
'AI'
if
info
.
pass
.
length
>
3
and
info
.
pass
[
0
...
3
]
==
'AI#'
or
info
.
pass
[
0
...
3
]
==
'AI_'
name
=
info
.
pass
.
slice
(
3
)
windbot
=
_
.
sample
_
.
filter
settings
.
modules
.
windbots
,
(
w
)
->
w
.
name
==
name
or
w
.
deck
==
name
if
!
windbot
ygopro
.
stoc_die
(
client
,
'主机密码不正确 (Invalid Windbot Name)'
)
return
else
windbot
=
_
.
sample
settings
.
modules
.
windbots
if
info
.
version
==
4921
#YGOMobile不更新,强行兼容
info
.
version
=
settings
.
version
struct
=
ygopro
.
structs
[
"CTOS_JoinGame"
]
struct
.
_setBuff
(
buffer
)
struct
.
set
(
"version"
,
info
.
version
)
buffer
=
struct
.
buffer
ygopro
.
stoc_send_chat
(
client
,
"您的版本号过低,可能出现未知问题,电脑用户请升级版本,YGOMobile用户请等待作者更新"
,
ygopro
.
constants
.
COLORS
.
BABYBLUE
)
room
=
ROOM_find_or_create_by_name
(
'AI#'
+
Math
.
floor
(
Math
.
random
()
*
100000
))
# 这个 AI# 没有特殊作用, 仅作为标记
if
!
room
ygopro
.
stoc_die
(
client
,
"服务器已经爆满,请稍候再试"
)
else
if
room
.
error
ygopro
.
stoc_die
(
client
,
room
.
error
)
else
room
.
windbot
=
windbot
room
.
private
=
true
#client.room = room
client
.
rid
=
_
.
indexOf
(
ROOM_all
,
room
)
room
.
connect
(
client
)
else
if
info
.
pass
.
length
and
settings
.
modules
.
mycard_auth
ygopro
.
stoc_send_chat
(
client
,
'正在读取用户信息...'
,
ygopro
.
constants
.
COLORS
.
BABYBLUE
)
ygopro
.
stoc_send_chat
(
client
,
'正在读取用户信息...'
,
ygopro
.
constants
.
COLORS
.
BABYBLUE
)
if
info
.
pass
.
length
<=
8
if
info
.
pass
.
length
<=
8
ygopro
.
stoc_die
(
client
,
'主机密码不正确 (Invalid Length)'
)
ygopro
.
stoc_die
(
client
,
'主机密码不正确 (Invalid Length)'
)
...
@@ -1272,8 +1284,6 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server)->
...
@@ -1272,8 +1284,6 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server)->
for
player
in
room
.
players
when
player
.
pos
!=
7
for
player
in
room
.
players
when
player
.
pos
!=
7
room
.
dueling_players
[
player
.
pos
]
=
player
room
.
dueling_players
[
player
.
pos
]
=
player
room
.
player_datas
.
push
ip
:
player
.
remoteAddress
,
name
:
player
.
name
room
.
player_datas
.
push
ip
:
player
.
remoteAddress
,
name
:
player
.
name
if
room
.
windbot
room
.
dueling_players
[
1
-
player
.
pos
]
=
{}
if
settings
.
modules
.
tips
if
settings
.
modules
.
tips
ygopro
.
stoc_send_random_tip
(
client
)
ygopro
.
stoc_send_random_tip
(
client
)
return
return
...
@@ -1289,11 +1299,17 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server)->
...
@@ -1289,11 +1299,17 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server)->
ygopro
.
stoc_send_chat
(
client
,
"YGOSrv233 指令帮助"
)
ygopro
.
stoc_send_chat
(
client
,
"YGOSrv233 指令帮助"
)
ygopro
.
stoc_send_chat
(
client
,
"/help 显示这个帮助信息"
)
ygopro
.
stoc_send_chat
(
client
,
"/help 显示这个帮助信息"
)
ygopro
.
stoc_send_chat
(
client
,
"/roomname 显示当前房间的名字"
)
ygopro
.
stoc_send_chat
(
client
,
"/roomname 显示当前房间的名字"
)
ygopro
.
stoc_send_chat
(
client
,
"/ai 添加一个AI"
)
if
settings
.
modules
.
enable_windbot
ygopro
.
stoc_send_chat
(
client
,
"/tip 显示一条提示"
)
if
settings
.
modules
.
tips
ygopro
.
stoc_send_chat
(
client
,
"/tip 显示一条提示"
)
if
settings
.
modules
.
tips
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
'/ai'
if
settings
.
modules
.
enable_windbot
windbot
=
_
.
sample
settings
.
modules
.
windbots
room
.
add_windbot
(
windbot
)
when
'/roomname'
when
'/roomname'
ygopro
.
stoc_send_chat
(
client
,
"您当前的房间名是 "
+
room
.
name
,
ygopro
.
constants
.
COLORS
.
BABYBLUE
)
if
room
ygopro
.
stoc_send_chat
(
client
,
"您当前的房间名是 "
+
room
.
name
,
ygopro
.
constants
.
COLORS
.
BABYBLUE
)
if
room
...
...
ygopro-server.js
View file @
fd0ca6d7
// Generated by CoffeeScript 1.10.0
// Generated by CoffeeScript 1.10.0
(
function
()
{
(
function
()
{
var
Cloud_replay_ids
,
Graveyard
,
ROOM_all
,
ROOM_ban_player
,
ROOM_find_by_name
,
ROOM_find_by_port
,
ROOM_find_or_create_by_name
,
ROOM_find_or_create_random
,
ROOM_players_banned
,
ROOM_players_oppentlist
,
ROOM_validate
,
Room
,
_
,
ban_user
,
bunyan
,
crypto
,
date
,
defaultconfig
,
execFile
,
fs
,
get_memory_usage
,
http
,
http_server
,
https
,
https_server
,
list
,
load_dialogues
,
load_tips
,
log
,
moment
,
nconf
,
net
,
options
,
os
,
path
,
pg
,
redis
,
redisdb
,
request
,
requestListener
,
roomlist
,
settings
,
spawn
,
spawnSync
,
tribute
,
url
,
users_cache
,
wait_room_start
,
ygopro
,
zlib
;
var
Cloud_replay_ids
,
Graveyard
,
ROOM_all
,
ROOM_ban_player
,
ROOM_find_by_name
,
ROOM_find_by_port
,
ROOM_find_or_create_
ai
,
ROOM_find_or_create_
by_name
,
ROOM_find_or_create_random
,
ROOM_players_banned
,
ROOM_players_oppentlist
,
ROOM_validate
,
Room
,
_
,
ban_user
,
bunyan
,
crypto
,
date
,
defaultconfig
,
execFile
,
fs
,
get_memory_usage
,
http
,
http_server
,
https
,
https_server
,
list
,
load_dialogues
,
load_tips
,
log
,
moment
,
nconf
,
net
,
options
,
os
,
path
,
pg
,
redis
,
redisdb
,
request
,
requestListener
,
roomlist
,
settings
,
spawn
,
spawnSync
,
tribute
,
url
,
users_cache
,
wait_room_start
,
ygopro
,
zlib
;
net
=
require
(
'
net
'
);
net
=
require
(
'
net
'
);
...
@@ -231,9 +231,13 @@
...
@@ -231,9 +231,13 @@
};
};
ROOM_find_or_create_by_name
=
function
(
name
,
player_ip
)
{
ROOM_find_or_create_by_name
=
function
(
name
,
player_ip
)
{
var
room
;
var
room
,
uname
;
if
(
settings
.
modules
.
enable_random_duel
&&
(
name
===
''
||
name
.
toUpperCase
()
===
'
S
'
||
name
.
toUpperCase
()
===
'
M
'
||
name
.
toUpperCase
()
===
'
T
'
))
{
uname
=
name
.
toUpperCase
();
return
ROOM_find_or_create_random
(
name
.
toUpperCase
(),
player_ip
);
if
(
settings
.
modules
.
enable_windbot
&&
(
uname
.
slice
(
0
,
2
)
===
'
AI
'
||
(
!
settings
.
modules
.
enable_random_duel
&&
uname
===
''
)))
{
return
ROOM_find_or_create_ai
(
name
);
}
if
(
settings
.
modules
.
enable_random_duel
&&
(
uname
===
''
||
uname
===
'
S
'
||
uname
===
'
M
'
||
uname
===
'
T
'
))
{
return
ROOM_find_or_create_random
(
uname
,
player_ip
);
}
}
if
(
room
=
ROOM_find_by_name
(
name
))
{
if
(
room
=
ROOM_find_by_name
(
name
))
{
return
room
;
return
room
;
...
@@ -276,7 +280,7 @@
...
@@ -276,7 +280,7 @@
});
});
if
(
result
)
{
if
(
result
)
{
result
.
welcome
=
'
对手已经在等你了,开始决斗吧!
'
;
result
.
welcome
=
'
对手已经在等你了,开始决斗吧!
'
;
}
else
{
}
else
if
(
get_memory_usage
()
<
90
)
{
type
=
type
?
type
:
'
S
'
;
type
=
type
?
type
:
'
S
'
;
name
=
type
+
'
,RANDOM#
'
+
Math
.
floor
(
Math
.
random
()
*
100000
);
name
=
type
+
'
,RANDOM#
'
+
Math
.
floor
(
Math
.
random
()
*
100000
);
result
=
new
Room
(
name
);
result
=
new
Room
(
name
);
...
@@ -284,6 +288,8 @@
...
@@ -284,6 +288,8 @@
result
.
max_player
=
max_player
;
result
.
max_player
=
max_player
;
result
.
welcome
=
'
已建立随机对战房间,正在等待对手!
'
;
result
.
welcome
=
'
已建立随机对战房间,正在等待对手!
'
;
result
.
deprecated
=
playerbanned
;
result
.
deprecated
=
playerbanned
;
}
else
{
return
null
;
}
}
if
(
result
.
random_type
===
'
M
'
)
{
if
(
result
.
random_type
===
'
M
'
)
{
result
.
welcome
=
result
.
welcome
+
'
\n
您进入了比赛模式的房间,我们推荐使用竞技卡组!
'
;
result
.
welcome
=
result
.
welcome
+
'
\n
您进入了比赛模式的房间,我们推荐使用竞技卡组!
'
;
...
@@ -291,6 +297,38 @@
...
@@ -291,6 +297,38 @@
return
result
;
return
result
;
};
};
ROOM_find_or_create_ai
=
function
(
name
)
{
var
ainame
,
result
,
room
,
windbot
;
if
(
name
===
''
)
{
name
=
'
AI
'
;
}
if
(
name
.
slice
(
0
,
3
)
===
'
AI_
'
)
{
name
=
'
AI#
'
+
name
.
slice
(
3
);
}
if
(
room
=
ROOM_find_by_name
(
name
))
{
return
room
;
}
else
if
(
name
===
'
AI
'
)
{
windbot
=
_
.
sample
(
settings
.
modules
.
windbots
);
name
=
'
AI#
'
+
Math
.
floor
(
Math
.
random
()
*
100000
);
}
else
if
(
ainame
=
name
.
split
(
'
#
'
)[
1
])
{
windbot
=
_
.
sample
(
_
.
filter
(
settings
.
modules
.
windbots
,
function
(
w
)
{
return
w
.
name
===
ainame
||
w
.
deck
===
ainame
;
}));
if
(
!
windbot
)
{
return
{
"
error
"
:
"
未找到该AI角色或卡组
"
};
}
name
=
name
+
'
,
'
+
Math
.
floor
(
Math
.
random
()
*
100000
);
}
else
{
windbot
=
_
.
sample
(
settings
.
modules
.
windbots
);
name
=
name
+
'
#
'
+
Math
.
floor
(
Math
.
random
()
*
100000
);
}
result
=
new
Room
(
name
);
result
.
windbot
=
windbot
;
return
result
;
};
ROOM_find_by_name
=
function
(
name
)
{
ROOM_find_by_name
=
function
(
name
)
{
var
result
;
var
result
;
result
=
_
.
find
(
ROOM_all
,
function
(
room
)
{
result
=
_
.
find
(
ROOM_all
,
function
(
room
)
{
...
@@ -562,7 +600,9 @@
...
@@ -562,7 +600,9 @@
});
});
});
});
if
(
_this
.
windbot
)
{
if
(
_this
.
windbot
)
{
request
.
get
(
"
http://127.0.0.1:2399/?name=
"
+
(
encodeURIComponent
(
_this
.
windbot
.
name
))
+
"
&deck=
"
+
(
encodeURIComponent
(
_this
.
windbot
.
deck
))
+
"
&host=127.0.0.1&port=
"
+
_this
.
port
+
"
&dialog=
"
+
(
encodeURIComponent
(
_this
.
windbot
.
dialog
))
+
"
&version=
"
+
settings
.
version
);
setTimeout
(
function
()
{
return
_this
.
add_windbot
(
_this
.
windbot
);
},
200
);
}
}
};
};
})(
this
));
})(
this
));
...
@@ -655,6 +695,22 @@
...
@@ -655,6 +695,22 @@
return
host_player
;
return
host_player
;
};
};
Room
.
prototype
.
add_windbot
=
function
(
botdata
)
{
this
.
windbot
=
botdata
;
request
({
url
:
"
http://127.0.0.1:
"
+
settings
.
modules
.
windbot_port
+
"
/?name=
"
+
(
encodeURIComponent
(
botdata
.
name
))
+
"
&deck=
"
+
(
encodeURIComponent
(
botdata
.
deck
))
+
"
&host=127.0.0.1&port=
"
+
settings
.
port
+
"
&dialog=
"
+
(
encodeURIComponent
(
botdata
.
dialog
))
+
"
&version=
"
+
settings
.
version
+
"
&password=
"
+
(
encodeURIComponent
(
this
.
name
))
},
(
function
(
_this
)
{
return
function
(
error
,
response
,
body
)
{
if
(
error
)
{
log
.
warn
(
'
windbot add error
'
,
error
,
_this
.
name
,
response
);
ygopro
.
stoc_send_chat_to_room
(
_this
,
"
添加AI失败,可尝试输入 /ai 重新添加
"
,
ygopro
.
constants
.
COLORS
.
RED
);
}
else
{
log
.
info
(
"
windbot added
"
);
}
};
})(
this
));
};
Room
.
prototype
.
connect
=
function
(
client
)
{
Room
.
prototype
.
connect
=
function
(
client
)
{
var
host_player
;
var
host_player
;
this
.
players
.
push
(
client
);
this
.
players
.
push
(
client
);
...
@@ -702,7 +758,7 @@
...
@@ -702,7 +758,7 @@
if
(
this
.
started
&&
this
.
disconnector
!==
'
server
'
&&
this
.
random_type
)
{
if
(
this
.
started
&&
this
.
disconnector
!==
'
server
'
&&
this
.
random_type
)
{
ROOM_ban_player
(
client
.
name
,
client
.
ip
,
"
强退
"
);
ROOM_ban_player
(
client
.
name
,
client
.
ip
,
"
强退
"
);
}
}
if
(
this
.
players
.
length
)
{
if
(
this
.
players
.
length
&&
!
(
this
.
windbot
&&
client
.
is_host
)
)
{
ygopro
.
stoc_send_chat_to_room
(
this
,
(
client
.
name
+
"
离开了游戏
"
)
+
(
error
?
"
:
"
+
error
:
''
));
ygopro
.
stoc_send_chat_to_room
(
this
,
(
client
.
name
+
"
离开了游戏
"
)
+
(
error
?
"
:
"
+
error
:
''
));
if
(
!
this
[
"
private
"
]
&&
!
this
.
started
&&
settings
.
modules
.
enable_websocket_roomlist
)
{
if
(
!
this
[
"
private
"
]
&&
!
this
.
started
&&
settings
.
modules
.
enable_websocket_roomlist
)
{
roomlist
.
update
(
this
);
roomlist
.
update
(
this
);
...
@@ -954,7 +1010,7 @@
...
@@ -954,7 +1010,7 @@
});
});
ygopro
.
ctos_follow
(
'
JOIN_GAME
'
,
false
,
function
(
buffer
,
info
,
client
,
server
)
{
ygopro
.
ctos_follow
(
'
JOIN_GAME
'
,
false
,
function
(
buffer
,
info
,
client
,
server
)
{
var
check
,
decrypted_buffer
,
finish
,
i
,
id
,
k
,
l
,
len
,
len1
,
name
,
ref
,
ref1
,
replay_id
,
room
,
secret
,
struct
,
windbot
;
var
check
,
decrypted_buffer
,
finish
,
i
,
id
,
k
,
l
,
len
,
len1
,
name
,
ref
,
ref1
,
replay_id
,
room
,
secret
,
struct
;
if
(
settings
.
modules
.
stop
)
{
if
(
settings
.
modules
.
stop
)
{
ygopro
.
stoc_die
(
client
,
settings
.
modules
.
stop
);
ygopro
.
stoc_die
(
client
,
settings
.
modules
.
stop
);
}
else
if
(
info
.
pass
.
toUpperCase
()
===
"
R
"
&&
settings
.
modules
.
enable_cloud_replay
)
{
}
else
if
(
info
.
pass
.
toUpperCase
()
===
"
R
"
&&
settings
.
modules
.
enable_cloud_replay
)
{
...
@@ -1007,41 +1063,9 @@
...
@@ -1007,41 +1063,9 @@
code
:
settings
.
version
code
:
settings
.
version
});
});
client
.
end
();
client
.
end
();
}
else
if
(
!
info
.
pass
.
length
&&
!
settings
.
modules
.
enable_random_duel
)
{
}
else
if
(
!
info
.
pass
.
length
&&
!
settings
.
modules
.
enable_random_duel
&&
!
settings
.
modules
.
enable_windbot
)
{
ygopro
.
stoc_die
(
client
,
"
房间名为空,请填写主机密码
"
);
ygopro
.
stoc_die
(
client
,
"
房间名为空,请填写主机密码
"
);
}
else
if
(
settings
.
modules
.
enable_windbot
&&
info
.
pass
.
slice
(
0
,
2
)
===
'
AI
'
)
{
}
else
if
(
info
.
pass
.
length
&&
settings
.
modules
.
mycard_auth
&&
info
.
pass
.
slice
(
0
,
2
)
!==
'
AI
'
)
{
if
(
info
.
pass
.
length
>
3
&&
info
.
pass
.
slice
(
0
,
3
)
===
'
AI#
'
||
info
.
pass
.
slice
(
0
,
3
)
===
'
AI_
'
)
{
name
=
info
.
pass
.
slice
(
3
);
windbot
=
_
.
sample
(
_
.
filter
(
settings
.
modules
.
windbots
,
function
(
w
)
{
return
w
.
name
===
name
||
w
.
deck
===
name
;
}));
if
(
!
windbot
)
{
ygopro
.
stoc_die
(
client
,
'
主机密码不正确 (Invalid Windbot Name)
'
);
return
;
}
}
else
{
windbot
=
_
.
sample
(
settings
.
modules
.
windbots
);
}
if
(
info
.
version
===
4921
)
{
info
.
version
=
settings
.
version
;
struct
=
ygopro
.
structs
[
"
CTOS_JoinGame
"
];
struct
.
_setBuff
(
buffer
);
struct
.
set
(
"
version
"
,
info
.
version
);
buffer
=
struct
.
buffer
;
ygopro
.
stoc_send_chat
(
client
,
"
您的版本号过低,可能出现未知问题,电脑用户请升级版本,YGOMobile用户请等待作者更新
"
,
ygopro
.
constants
.
COLORS
.
BABYBLUE
);
}
room
=
ROOM_find_or_create_by_name
(
'
AI#
'
+
Math
.
floor
(
Math
.
random
()
*
100000
));
if
(
!
room
)
{
ygopro
.
stoc_die
(
client
,
"
服务器已经爆满,请稍候再试
"
);
}
else
if
(
room
.
error
)
{
ygopro
.
stoc_die
(
client
,
room
.
error
);
}
else
{
room
.
windbot
=
windbot
;
room
[
"
private
"
]
=
true
;
client
.
rid
=
_
.
indexOf
(
ROOM_all
,
room
);
room
.
connect
(
client
);
}
}
else
if
(
info
.
pass
.
length
&&
settings
.
modules
.
mycard_auth
)
{
ygopro
.
stoc_send_chat
(
client
,
'
正在读取用户信息...
'
,
ygopro
.
constants
.
COLORS
.
BABYBLUE
);
ygopro
.
stoc_send_chat
(
client
,
'
正在读取用户信息...
'
,
ygopro
.
constants
.
COLORS
.
BABYBLUE
);
if
(
info
.
pass
.
length
<=
8
)
{
if
(
info
.
pass
.
length
<=
8
)
{
ygopro
.
stoc_die
(
client
,
'
主机密码不正确 (Invalid Length)
'
);
ygopro
.
stoc_die
(
client
,
'
主机密码不正确 (Invalid Length)
'
);
...
@@ -1061,7 +1085,7 @@
...
@@ -1061,7 +1085,7 @@
return
(
checksum
&
0xFF
)
===
0
;
return
(
checksum
&
0xFF
)
===
0
;
};
};
finish
=
function
(
buffer
)
{
finish
=
function
(
buffer
)
{
var
action
,
opt1
,
opt2
,
opt3
,
options
;
var
action
,
name
,
opt1
,
opt2
,
opt3
,
options
,
room
;
action
=
buffer
.
readUInt8
(
1
)
>>
4
;
action
=
buffer
.
readUInt8
(
1
)
>>
4
;
if
(
buffer
!==
decrypted_buffer
&&
(
action
===
1
||
action
===
2
||
action
===
4
))
{
if
(
buffer
!==
decrypted_buffer
&&
(
action
===
1
||
action
===
2
||
action
===
4
))
{
ygopro
.
stoc_die
(
client
,
'
主机密码不正确 (Unauthorized)
'
);
ygopro
.
stoc_die
(
client
,
'
主机密码不正确 (Unauthorized)
'
);
...
@@ -1564,9 +1588,6 @@
...
@@ -1564,9 +1588,6 @@
ip
:
player
.
remoteAddress
,
ip
:
player
.
remoteAddress
,
name
:
player
.
name
name
:
player
.
name
});
});
if
(
room
.
windbot
)
{
room
.
dueling_players
[
1
-
player
.
pos
]
=
{};
}
}
}
}
}
if
(
settings
.
modules
.
tips
)
{
if
(
settings
.
modules
.
tips
)
{
...
@@ -1575,7 +1596,7 @@
...
@@ -1575,7 +1596,7 @@
});
});
ygopro
.
ctos_follow
(
'
CHAT
'
,
true
,
function
(
buffer
,
info
,
client
,
server
)
{
ygopro
.
ctos_follow
(
'
CHAT
'
,
true
,
function
(
buffer
,
info
,
client
,
server
)
{
var
cancel
,
msg
,
oldmsg
,
room
,
struct
;
var
cancel
,
msg
,
oldmsg
,
room
,
struct
,
windbot
;
room
=
ROOM_all
[
client
.
rid
];
room
=
ROOM_all
[
client
.
rid
];
if
(
!
room
)
{
if
(
!
room
)
{
return
;
return
;
...
@@ -1590,6 +1611,9 @@
...
@@ -1590,6 +1611,9 @@
ygopro
.
stoc_send_chat
(
client
,
"
YGOSrv233 指令帮助
"
);
ygopro
.
stoc_send_chat
(
client
,
"
YGOSrv233 指令帮助
"
);
ygopro
.
stoc_send_chat
(
client
,
"
/help 显示这个帮助信息
"
);
ygopro
.
stoc_send_chat
(
client
,
"
/help 显示这个帮助信息
"
);
ygopro
.
stoc_send_chat
(
client
,
"
/roomname 显示当前房间的名字
"
);
ygopro
.
stoc_send_chat
(
client
,
"
/roomname 显示当前房间的名字
"
);
if
(
settings
.
modules
.
enable_windbot
)
{
ygopro
.
stoc_send_chat
(
client
,
"
/ai 添加一个AI
"
);
}
if
(
settings
.
modules
.
tips
)
{
if
(
settings
.
modules
.
tips
)
{
ygopro
.
stoc_send_chat
(
client
,
"
/tip 显示一条提示
"
);
ygopro
.
stoc_send_chat
(
client
,
"
/tip 显示一条提示
"
);
}
}
...
@@ -1599,6 +1623,12 @@
...
@@ -1599,6 +1623,12 @@
ygopro
.
stoc_send_random_tip
(
client
);
ygopro
.
stoc_send_random_tip
(
client
);
}
}
break
;
break
;
case
'
/ai
'
:
if
(
settings
.
modules
.
enable_windbot
)
{
windbot
=
_
.
sample
(
settings
.
modules
.
windbots
);
room
.
add_windbot
(
windbot
);
}
break
;
case
'
/roomname
'
:
case
'
/roomname
'
:
if
(
room
)
{
if
(
room
)
{
ygopro
.
stoc_send_chat
(
client
,
"
您当前的房间名是
"
+
room
.
name
,
ygopro
.
constants
.
COLORS
.
BABYBLUE
);
ygopro
.
stoc_send_chat
(
client
,
"
您当前的房间名是
"
+
room
.
name
,
ygopro
.
constants
.
COLORS
.
BABYBLUE
);
...
...
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