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
e24ddd92
Commit
e24ddd92
authored
Jun 23, 2020
by
nanahira
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'mc'
parents
feefd40d
3547c9ab
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
14 deletions
+37
-14
YGOProMessages.js
YGOProMessages.js
+17
-6
YGOProMessages.ts
YGOProMessages.ts
+20
-8
No files found.
YGOProMessages.js
View file @
e24ddd92
...
@@ -117,12 +117,9 @@ class YGOProMessagesHelper {
...
@@ -117,12 +117,9 @@ class YGOProMessagesHelper {
}
}
return
parseInt
(
translatedProto
);
return
parseInt
(
translatedProto
);
}
}
sendMessage
(
socket
,
protostr
,
info
)
{
prepareMessage
(
protostr
,
info
)
{
const
{
direction
,
proto
}
=
this
.
getDirectionAndProto
(
protostr
);
const
{
direction
,
proto
}
=
this
.
getDirectionAndProto
(
protostr
);
let
buffer
;
let
buffer
;
if
(
!
socket
.
remoteAddress
)
{
return
;
}
//console.log(proto, this.proto_structs[direction][proto]);
//console.log(proto, this.proto_structs[direction][proto]);
//const directionProtoList = this.constants[direction];
//const directionProtoList = this.constants[direction];
if
(
typeof
info
===
'
undefined
'
)
{
if
(
typeof
info
===
'
undefined
'
)
{
...
@@ -139,13 +136,27 @@ class YGOProMessagesHelper {
...
@@ -139,13 +136,27 @@ class YGOProMessagesHelper {
}
}
const
translatedProto
=
this
.
translateProto
(
proto
,
direction
);
const
translatedProto
=
this
.
translateProto
(
proto
,
direction
);
let
sendBuffer
=
Buffer
.
allocUnsafe
(
3
+
(
buffer
?
buffer
.
length
:
0
));
let
sendBuffer
=
Buffer
.
allocUnsafe
(
3
+
(
buffer
?
buffer
.
length
:
0
));
sendBuffer
.
writeUInt16LE
(
buffer
.
length
+
1
,
0
);
sendBuffer
.
writeUInt8
(
translatedProto
,
2
);
if
(
buffer
)
{
if
(
buffer
)
{
sendBuffer
.
writeUInt16LE
(
buffer
.
length
+
1
,
0
);
sendBuffer
.
writeUInt8
(
translatedProto
,
2
);
buffer
.
copy
(
sendBuffer
,
3
);
buffer
.
copy
(
sendBuffer
,
3
);
}
}
else
{
sendBuffer
.
writeUInt16LE
(
1
,
0
);
sendBuffer
.
writeUInt8
(
translatedProto
,
2
);
}
return
buffer
;
}
sendMessage
(
socket
,
protostr
,
info
)
{
const
sendBuffer
=
this
.
prepareMessage
(
protostr
,
info
);
socket
.
write
(
sendBuffer
);
socket
.
write
(
sendBuffer
);
}
}
sendMessageAsync
(
socket
,
protostr
,
info
)
{
const
sendBuffer
=
this
.
prepareMessage
(
protostr
,
info
);
return
new
Promise
(
done
=>
{
socket
.
write
(
sendBuffer
,
done
);
});
}
addHandler
(
protostr
,
handler
,
synchronous
,
priority
)
{
addHandler
(
protostr
,
handler
,
synchronous
,
priority
)
{
if
(
priority
<
0
||
priority
>
4
)
{
if
(
priority
<
0
||
priority
>
4
)
{
throw
"
Invalid priority:
"
+
priority
;
throw
"
Invalid priority:
"
+
priority
;
...
...
YGOProMessages.ts
View file @
e24ddd92
...
@@ -147,15 +147,12 @@ export class YGOProMessagesHelper {
...
@@ -147,15 +147,12 @@ export class YGOProMessagesHelper {
return
parseInt
(
translatedProto
);
return
parseInt
(
translatedProto
);
}
}
sendMessage
(
socket
:
net
.
Socket
,
protostr
:
string
,
info
:
string
|
Buffer
|
any
)
{
prepareMessage
(
protostr
:
string
,
info
?:
string
|
Buffer
|
any
):
Buffer
{
const
{
const
{
direction
,
direction
,
proto
proto
}
=
this
.
getDirectionAndProto
(
protostr
);
}
=
this
.
getDirectionAndProto
(
protostr
);
let
buffer
:
Buffer
;
let
buffer
:
Buffer
;
if
(
!
socket
.
remoteAddress
)
{
return
;
}
//console.log(proto, this.proto_structs[direction][proto]);
//console.log(proto, this.proto_structs[direction][proto]);
//const directionProtoList = this.constants[direction];
//const directionProtoList = this.constants[direction];
if
(
typeof
info
===
'
undefined
'
)
{
if
(
typeof
info
===
'
undefined
'
)
{
...
@@ -170,14 +167,29 @@ export class YGOProMessagesHelper {
...
@@ -170,14 +167,29 @@ export class YGOProMessagesHelper {
}
}
const
translatedProto
=
this
.
translateProto
(
proto
,
direction
);
const
translatedProto
=
this
.
translateProto
(
proto
,
direction
);
let
sendBuffer
=
Buffer
.
allocUnsafe
(
3
+
(
buffer
?
buffer
.
length
:
0
));
let
sendBuffer
=
Buffer
.
allocUnsafe
(
3
+
(
buffer
?
buffer
.
length
:
0
));
sendBuffer
.
writeUInt16LE
(
buffer
.
length
+
1
,
0
);
sendBuffer
.
writeUInt8
(
translatedProto
,
2
);
if
(
buffer
)
{
if
(
buffer
)
{
buffer
.
copy
(
sendBuffer
,
3
)
sendBuffer
.
writeUInt16LE
(
buffer
.
length
+
1
,
0
);
sendBuffer
.
writeUInt8
(
translatedProto
,
2
);
buffer
.
copy
(
sendBuffer
,
3
);
}
else
{
sendBuffer
.
writeUInt16LE
(
1
,
0
);
sendBuffer
.
writeUInt8
(
translatedProto
,
2
);
}
}
return
buffer
;
}
sendMessage
(
socket
:
net
.
Socket
,
protostr
:
string
,
info
?:
string
|
Buffer
|
any
)
{
const
sendBuffer
=
this
.
prepareMessage
(
protostr
,
info
);
socket
.
write
(
sendBuffer
);
socket
.
write
(
sendBuffer
);
}
}
sendMessageAsync
(
socket
:
net
.
Socket
,
protostr
:
string
,
info
?:
string
|
Buffer
|
any
):
Promise
<
Error
>
{
const
sendBuffer
=
this
.
prepareMessage
(
protostr
,
info
);
return
new
Promise
(
done
=>
{
socket
.
write
(
sendBuffer
,
done
);
});
}
addHandler
(
protostr
:
string
,
handler
:
(
buffer
:
Buffer
,
info
:
any
,
datas
:
Buffer
[],
params
:
any
)
=>
Promise
<
boolean
>
,
synchronous
:
boolean
,
priority
:
number
)
{
addHandler
(
protostr
:
string
,
handler
:
(
buffer
:
Buffer
,
info
:
any
,
datas
:
Buffer
[],
params
:
any
)
=>
Promise
<
boolean
>
,
synchronous
:
boolean
,
priority
:
number
)
{
if
(
priority
<
0
||
priority
>
4
)
{
if
(
priority
<
0
||
priority
>
4
)
{
throw
"
Invalid priority:
"
+
priority
;
throw
"
Invalid priority:
"
+
priority
;
...
@@ -196,7 +208,7 @@ export class YGOProMessagesHelper {
...
@@ -196,7 +208,7 @@ export class YGOProMessagesHelper {
handlerCollection
.
get
(
translatedProto
).
push
(
handlerObj
);
handlerCollection
.
get
(
translatedProto
).
push
(
handlerObj
);
}
}
async
handleBuffer
(
messageBuffer
:
Buffer
,
direction
:
string
,
protoFilter
:
string
[],
params
:
any
):
Promise
<
HandleResult
>
{
async
handleBuffer
(
messageBuffer
:
Buffer
,
direction
:
string
,
protoFilter
?:
string
[],
params
?
:
any
):
Promise
<
HandleResult
>
{
let
feedback
:
Feedback
=
null
;
let
feedback
:
Feedback
=
null
;
let
messageLength
=
0
;
let
messageLength
=
0
;
let
bufferProto
=
0
;
let
bufferProto
=
0
;
...
...
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