Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygoreplay-plugin
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
MyCard
ygoreplay-plugin
Commits
6e05bb51
Commit
6e05bb51
authored
Oct 11, 2021
by
Sophia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update built binary
parent
61cd67db
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
195 additions
and
0 deletions
+195
-0
dist/index.js
dist/index.js
+195
-0
No files found.
dist/index.js
0 → 100644
View file @
6e05bb51
"
use strict
"
;
var
__awaiter
=
(
this
&&
this
.
__awaiter
)
||
function
(
thisArg
,
_arguments
,
P
,
generator
)
{
function
adopt
(
value
)
{
return
value
instanceof
P
?
value
:
new
P
(
function
(
resolve
)
{
resolve
(
value
);
});
}
return
new
(
P
||
(
P
=
Promise
))(
function
(
resolve
,
reject
)
{
function
fulfilled
(
value
)
{
try
{
step
(
generator
.
next
(
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
rejected
(
value
)
{
try
{
step
(
generator
[
"
throw
"
](
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
step
(
result
)
{
result
.
done
?
resolve
(
result
.
value
)
:
adopt
(
result
.
value
).
then
(
fulfilled
,
rejected
);
}
step
((
generator
=
generator
.
apply
(
thisArg
,
_arguments
||
[])).
next
());
});
};
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
value
:
true
});
const
node_fetch_1
=
require
(
"
node-fetch
"
);
const
moment
=
require
(
"
moment
"
);
const
FormData
=
require
(
"
form-data
"
);
function
formatTime
(
t
)
{
return
t
.
unix
();
}
function
compressData
(
jsonData
,
replays
)
{
const
headerLengthBuffer
=
Buffer
.
alloc
(
4
);
const
headerContentBuffer
=
Buffer
.
from
(
jsonData
,
"
utf8
"
);
headerLengthBuffer
.
writeUInt32BE
(
headerContentBuffer
.
length
);
let
replayBuffer
=
null
;
replays
.
forEach
(
replayData
=>
{
const
replayDataLengthBuffer
=
Buffer
.
alloc
(
4
);
replayDataLengthBuffer
.
writeUInt32BE
(
replayData
.
length
,
0
);
if
(
!
replayBuffer
)
{
replayBuffer
=
Buffer
.
concat
([
replayDataLengthBuffer
,
replayData
]);
}
else
{
replayBuffer
=
Buffer
.
concat
([
replayBuffer
,
replayDataLengthBuffer
,
replayData
]);
}
});
return
Buffer
.
concat
([
headerLengthBuffer
,
headerContentBuffer
,
replayBuffer
]);
}
function
uploadResult
(
room
)
{
try
{
if
(
!
room
.
finishedAt
)
{
room
.
finishedAt
=
[];
}
room
.
finishedAt
.
push
(
moment
());
const
data
=
{
roomSettings
:
Object
.
assign
(
Object
.
assign
({},
room
.
hostinfo
),
{
lflist
:
Object
.
assign
(
Object
.
assign
({},
lflists
[
room
.
hostinfo
.
lflist
]),
{
date
:
lflists
[
room
.
hostinfo
.
lflist
].
date
.
add
(
1
,
"
day
"
).
format
(
"
YYYY.MM
"
)
})
}),
players
:
room
.
customPlayerInformation
,
startedAt
:
room
.
startedAt
.
map
(
formatTime
),
finishedAt
:
room
.
finishedAt
.
map
(
formatTime
),
type
:
room
.
arena
||
"
normal
"
,
isRandomMatch
:
Boolean
(
room
.
random_type
),
};
room
.
replaySaved
=
true
;
const
compressedData
=
compressData
(
JSON
.
stringify
(
data
),
room
.
replays
);
const
formData
=
new
FormData
();
formData
.
append
(
"
data
"
,
compressedData
,
{
filename
:
"
data.bin
"
,
});
(()
=>
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
const
response
=
yield
(
0
,
node_fetch_1
.
default
)(
"
http://10.198.1.45:3619/replay/upload
"
,
{
method
:
"
POST
"
,
body
:
formData
,
headers
:
formData
.
getHeaders
(),
});
if
(
!
response
.
ok
||
response
.
status
===
500
)
{
throw
new
Error
(
"
Status Code
"
+
response
.
status
);
}
const
data
=
(
yield
response
.
json
());
if
(
data
.
status
===
500
)
{
throw
new
Error
(
data
.
message
);
}
}))().
catch
(
e
=>
{
log
.
warn
(
`YGOReplay data collecting plugin error:
${
e
.
message
}
`
);
});
}
catch
(
e
)
{
log
.
warn
(
`YGOReplay: an error occurred during uploading match result:
${
e
.
message
}
`
);
}
}
ygopro
.
stoc_follow
(
"
DUEL_START
"
,
false
,
(
buffer
,
info
,
client
)
=>
__awaiter
(
void
0
,
void
0
,
void
0
,
function
*
()
{
try
{
if
(
client
.
pos
!==
0
)
{
return
true
;
}
const
room
=
ROOM_all
[
client
.
rid
];
if
(
room
.
hostinfo
.
mode
===
2
||
Boolean
(
room
.
windbot
))
{
return
true
;
}
if
(
!
room
.
startedAt
)
{
room
.
startedAt
=
[];
}
room
.
startedAt
.
push
(
moment
());
if
(
!
room
.
customPlayerInformation
)
{
room
.
customPlayerInformation
=
room
.
dueling_players
.
map
(
player
=>
{
return
{
ip
:
player
.
ip
,
name
:
player
.
name
,
joinTime
:
moment
(
player
.
join_time
).
format
(
"
YYYY-MM-DD HH:mm:ss
"
),
pos
:
player
.
pos
,
lang
:
player
.
lang
,
pass
:
player
.
pass
,
sidedDeck
:
[
{
main
:
player
.
main
,
side
:
player
.
side
,
},
],
};
});
}
}
catch
(
e
)
{
log
.
warn
(
`YGOReplay: an error occurred during processing DUEL_START message:
${
e
.
message
}
`
);
}
return
true
;
}));
ygopro
.
stoc_follow_after
(
"
CHANGE_SIDE
"
,
false
,
(
buffer
,
info
,
client
)
=>
__awaiter
(
void
0
,
void
0
,
void
0
,
function
*
()
{
try
{
client
.
needToChangeSide
=
true
;
if
(
client
.
pos
===
0
)
{
return
false
;
}
const
room
=
ROOM_all
[
client
.
rid
];
if
(
!
room
||
Boolean
(
room
.
windbot
))
{
return
false
;
}
if
(
!
room
.
finishedAt
)
{
room
.
finishedAt
=
[];
}
room
.
finishedAt
.
push
(
moment
());
}
catch
(
e
)
{
log
.
warn
(
`YGOReplay: an error occurred during processing CHANGE_SIDE message:
${
e
.
message
}
`
);
}
return
false
;
}));
ygopro
.
stoc_follow_after
(
"
REPLAY
"
,
false
,
(
buffer
,
info
,
client
)
=>
__awaiter
(
void
0
,
void
0
,
void
0
,
function
*
()
{
try
{
const
room
=
ROOM_all
[
client
.
rid
];
if
(
Boolean
(
room
.
windbot
))
{
return
true
;
}
if
(
client
.
pos
===
0
)
{
uploadResult
(
room
);
}
}
catch
(
e
)
{
log
.
warn
(
`YGOReplay: an error occurred during processing REPLAY message:
${
e
.
message
}
`
);
}
return
false
;
}));
ygopro
.
ctos_follow_after
(
"
UPDATE_DECK
"
,
false
,
(
buffer
,
info
,
client
)
=>
__awaiter
(
void
0
,
void
0
,
void
0
,
function
*
()
{
try
{
const
room
=
ROOM_all
[
client
.
rid
];
if
(
!
room
||
Boolean
(
room
.
windbot
))
{
return
false
;
}
if
(
!
room
.
customPlayerInformation
)
{
return
false
;
}
const
customPlayerInformation
=
room
.
customPlayerInformation
.
find
(
player
=>
player
.
pos
===
client
.
pos
);
if
(
!
customPlayerInformation
)
{
return
false
;
}
const
player
=
room
.
dueling_players
.
find
(
p
=>
p
.
pos
===
client
.
pos
);
if
(
!
player
)
{
return
false
;
}
if
(
client
.
needToChangeSide
)
{
customPlayerInformation
.
sidedDeck
.
push
({
main
:
player
.
main
,
side
:
player
.
side
,
});
client
.
needToChangeSide
=
false
;
}
}
catch
(
e
)
{
log
.
warn
(
`YGOReplay: an error occurred during processing UPDATE_DECK message:
${
e
.
message
}
`
);
}
return
false
;
}));
(()
=>
{
const
oldSTOCSend
=
ygopro
.
stoc_send
.
bind
(
ygopro
);
ygopro
.
stoc_send
=
(
client
,
message
,
buffer
)
=>
{
try
{
if
(
message
!==
"
REPLAY
"
)
{
return
oldSTOCSend
(
client
,
message
,
buffer
);
}
const
room
=
ROOM_all
[
client
.
rid
];
if
(
room
&&
client
.
pos
===
0
&&
!
room
.
replaySaved
&&
room
.
customPlayerInformation
&&
!
room
.
windbot
)
{
uploadResult
(
room
);
}
}
catch
(
e
)
{
log
.
warn
(
`YGOReplay: an error occurred during processing UPDATE_DECK message:
${
e
.
message
}
`
);
}
return
oldSTOCSend
(
client
,
message
,
buffer
);
};
})();
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