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
ec34713f
Commit
ec34713f
authored
Feb 07, 2026
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
migrate struct.js to ygopro-msg-encode
parent
72fc9542
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
180 additions
and
679 deletions
+180
-679
YGOProMessages.js
YGOProMessages.js
+76
-69
YGOProMessages.ts
YGOProMessages.ts
+96
-89
data/structs.json
data/structs.json
+0
-116
data/typedefs.json
data/typedefs.json
+0
-6
load-constants.js
load-constants.js
+3
-0
load-constants.ts
load-constants.ts
+4
-0
struct.js
struct.js
+0
-330
ygopro-server.coffee
ygopro-server.coffee
+0
-2
ygopro-server.js
ygopro-server.js
+0
-2
ygopro.coffee
ygopro.coffee
+0
-24
ygopro.js
ygopro.js
+1
-41
No files found.
YGOProMessages.js
View file @
ec34713f
...
@@ -3,17 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
...
@@ -3,17 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return
(
mod
&&
mod
.
__esModule
)
?
mod
:
{
"
default
"
:
mod
};
return
(
mod
&&
mod
.
__esModule
)
?
mod
:
{
"
default
"
:
mod
};
};
};
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
value
:
true
});
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
value
:
true
});
exports
.
YGOProMessagesHelper
=
void
0
;
exports
.
YGOProMessagesHelper
=
exports
.
LegacyStruct
=
exports
.
LegacyStructInst
=
void
0
;
const
struct_1
=
require
(
"
./struct
"
);
const
underscore_1
=
__importDefault
(
require
(
"
underscore
"
));
const
underscore_1
=
__importDefault
(
require
(
"
underscore
"
));
const
structs_json_1
=
__importDefault
(
require
(
"
./data/structs.json
"
));
const
typedefs_json_1
=
__importDefault
(
require
(
"
./data/typedefs.json
"
));
const
proto_structs_json_1
=
__importDefault
(
require
(
"
./data/proto_structs.json
"
));
const
load_constants_1
=
__importDefault
(
require
(
"
./load-constants
"
));
const
load_constants_1
=
__importDefault
(
require
(
"
./load-constants
"
));
const
ygopro_msg_encode_1
=
require
(
"
ygopro-msg-encode
"
);
const
ygopro_msg_struct_compat_1
=
require
(
"
./ygopro-msg-struct-compat
"
);
const
proto_structs_json_1
=
__importDefault
(
require
(
"
./data/proto_structs.json
"
));
class
Handler
{
class
Handler
{
constructor
(
handler
,
synchronous
)
{
constructor
(
handler
,
synchronous
)
{
this
.
handler
=
handler
;
this
.
handler
=
handler
;
this
.
synchronous
=
synchronous
||
false
;
this
.
synchronous
=
synchronous
;
}
}
async
handle
(
buffer
,
info
,
datas
,
params
)
{
async
handle
(
buffer
,
info
,
datas
,
params
)
{
if
(
this
.
synchronous
)
{
if
(
this
.
synchronous
)
{
...
@@ -27,8 +26,50 @@ class Handler {
...
@@ -27,8 +26,50 @@ class Handler {
}
}
}
}
}
}
class
LegacyStructInst
{
constructor
(
cls
)
{
this
.
cls
=
cls
;
}
_setBuff
(
buff
)
{
this
.
buffer
=
buff
;
}
set
(
field
,
value
)
{
if
(
!
this
.
buffer
||
!
this
.
cls
)
return
;
const
inst
=
(
0
,
ygopro_msg_struct_compat_1
.
applyYGOProMsgStructCompat
)(
new
this
.
cls
().
fromPayload
(
this
.
buffer
));
inst
[
field
]
=
value
;
const
parsed
=
Buffer
.
from
(
inst
.
toPayload
());
if
(
parsed
.
length
>=
this
.
buffer
.
length
)
{
// slice it down
parsed
.
copy
(
this
.
buffer
,
0
,
0
,
this
.
buffer
.
length
);
}
else
{
// copy a small part only
parsed
.
copy
(
this
.
buffer
,
0
,
0
,
parsed
.
length
);
}
}
}
exports
.
LegacyStructInst
=
LegacyStructInst
;
class
LegacyStruct
{
constructor
(
helper
)
{
this
.
helper
=
helper
;
this
.
protoClasses
=
new
Map
();
for
(
const
[
direction
,
list
]
of
Object
.
entries
(
proto_structs_json_1
.
default
))
{
for
(
const
[
protoStr
,
structName
]
of
Object
.
entries
(
list
))
{
if
(
!
structName
)
continue
;
this
.
protoClasses
.
set
(
structName
,
this
.
helper
.
getProtoClass
(
protoStr
,
direction
));
}
}
}
get
(
structName
)
{
return
new
LegacyStructInst
(
this
.
protoClasses
.
get
(
structName
));
}
}
exports
.
LegacyStruct
=
LegacyStruct
;
class
YGOProMessagesHelper
{
class
YGOProMessagesHelper
{
constructor
(
singleHandleLimit
)
{
constructor
(
singleHandleLimit
=
1000
)
{
this
.
singleHandleLimit
=
singleHandleLimit
;
this
.
handlers
=
{
this
.
handlers
=
{
STOC
:
[
new
Map
(),
STOC
:
[
new
Map
(),
new
Map
(),
new
Map
(),
...
@@ -43,56 +84,8 @@ class YGOProMessagesHelper {
...
@@ -43,56 +84,8 @@ class YGOProMessagesHelper {
new
Map
(),
new
Map
(),
]
]
};
};
this
.
initDatas
();
this
.
initStructs
();
if
(
singleHandleLimit
)
{
this
.
singleHandleLimit
=
singleHandleLimit
;
}
else
{
this
.
singleHandleLimit
=
1000
;
}
}
initDatas
()
{
this
.
structs_declaration
=
structs_json_1
.
default
;
this
.
typedefs
=
typedefs_json_1
.
default
;
this
.
proto_structs
=
proto_structs_json_1
.
default
;
this
.
constants
=
(
0
,
load_constants_1
.
default
)();
this
.
constants
=
(
0
,
load_constants_1
.
default
)();
}
this
.
structs
=
new
LegacyStruct
(
this
);
initStructs
()
{
this
.
structs
=
new
Map
();
for
(
let
name
in
this
.
structs_declaration
)
{
const
declaration
=
this
.
structs_declaration
[
name
];
let
result
=
(
0
,
struct_1
.
Struct
)();
for
(
let
field
of
declaration
)
{
if
(
field
.
encoding
)
{
switch
(
field
.
encoding
)
{
case
"
UTF-16LE
"
:
result
.
chars
(
field
.
name
,
field
.
length
*
2
,
field
.
encoding
);
break
;
default
:
throw
`unsupported encoding:
${
field
.
encoding
}
`
;
}
}
else
{
let
type
=
field
.
type
;
if
(
this
.
typedefs
[
type
])
{
type
=
this
.
typedefs
[
type
];
}
if
(
field
.
length
)
{
result
.
array
(
field
.
name
,
field
.
length
,
type
);
//不支持结构体
}
else
{
if
(
this
.
structs
.
has
(
type
))
{
result
.
struct
(
field
.
name
,
this
.
structs
.
get
(
type
));
}
else
{
result
[
type
](
field
.
name
);
}
}
}
}
this
.
structs
.
set
(
name
,
result
);
}
}
}
getDirectionAndProto
(
protoStr
)
{
getDirectionAndProto
(
protoStr
)
{
const
protoStrMatch
=
protoStr
.
match
(
/^
(
STOC|CTOS
)
_
([
_A-Z
]
+
)
$/
);
const
protoStrMatch
=
protoStr
.
match
(
/^
(
STOC|CTOS
)
_
([
_A-Z
]
+
)
$/
);
...
@@ -117,11 +110,27 @@ class YGOProMessagesHelper {
...
@@ -117,11 +110,27 @@ class YGOProMessagesHelper {
}
}
return
parseInt
(
translatedProto
);
return
parseInt
(
translatedProto
);
}
}
getProtoClass
(
proto
,
direction
)
{
const
identifier
=
typeof
proto
===
'
number
'
?
proto
:
this
.
translateProto
(
proto
,
direction
);
const
registry
=
direction
===
'
CTOS
'
?
ygopro_msg_encode_1
.
YGOProCtos
:
direction
===
'
STOC
'
?
ygopro_msg_encode_1
.
YGOProStoc
:
null
;
if
(
!
registry
)
{
throw
`Invalid direction:
${
direction
}
`
;
}
return
registry
.
get
(
identifier
);
}
classToProtoStr
(
cls
)
{
const
registry
=
cls
.
prototype
instanceof
ygopro_msg_encode_1
.
YGOProCtosBase
?
ygopro_msg_encode_1
.
YGOProCtos
:
cls
.
prototype
instanceof
ygopro_msg_encode_1
.
YGOProStocBase
?
ygopro_msg_encode_1
.
YGOProStoc
:
null
;
if
(
!
registry
)
{
throw
`Invalid class:
${
cls
.
name
}
`
;
}
const
identifier
=
cls
.
identifier
;
const
direction
=
cls
.
prototype
instanceof
ygopro_msg_encode_1
.
YGOProCtosBase
?
'
CTOS
'
:
'
STOC
'
;
return
`
${
direction
}
_
${
this
.
constants
[
direction
][
identifier
]}
`
;
}
prepareMessage
(
protostr
,
info
)
{
prepareMessage
(
protostr
,
info
)
{
const
{
direction
,
proto
}
=
this
.
getDirectionAndProto
(
protostr
);
const
{
direction
,
proto
}
=
this
.
getDirectionAndProto
(
protostr
);
const
translatedProto
=
this
.
translateProto
(
proto
,
direction
);
let
buffer
;
let
buffer
;
//console.log(proto, this.proto_structs[direction][proto]);
//const directionProtoList = this.constants[direction];
if
(
typeof
info
===
'
undefined
'
)
{
if
(
typeof
info
===
'
undefined
'
)
{
buffer
=
null
;
buffer
=
null
;
}
}
...
@@ -129,12 +138,12 @@ class YGOProMessagesHelper {
...
@@ -129,12 +138,12 @@ class YGOProMessagesHelper {
buffer
=
info
;
buffer
=
info
;
}
}
else
{
else
{
let
struct
=
this
.
structs
.
get
(
this
.
proto_structs
[
direction
][
proto
]);
const
protoCls
=
this
.
getProtoClass
(
translatedProto
,
direction
);
struct
.
allocate
();
if
(
!
protoCls
)
{
struct
.
set
(
info
);
throw
`No proto class for
${
protostr
}
`
;
buffer
=
struct
.
buffer
();
}
buffer
=
Buffer
.
from
((
0
,
ygopro_msg_struct_compat_1
.
fromPartialCompat
)(
protoCls
,
info
).
toPayload
());
}
}
const
translatedProto
=
this
.
translateProto
(
proto
,
direction
);
let
sendBuffer
=
Buffer
.
allocUnsafe
(
3
+
(
buffer
?
buffer
.
length
:
0
));
let
sendBuffer
=
Buffer
.
allocUnsafe
(
3
+
(
buffer
?
buffer
.
length
:
0
));
if
(
buffer
)
{
if
(
buffer
)
{
sendBuffer
.
writeUInt16LE
(
buffer
.
length
+
1
,
0
);
sendBuffer
.
writeUInt16LE
(
buffer
.
length
+
1
,
0
);
...
@@ -231,13 +240,11 @@ class YGOProMessagesHelper {
...
@@ -231,13 +240,11 @@ class YGOProMessagesHelper {
}
}
const
handlerCollection
=
this
.
handlers
[
direction
][
priority
];
const
handlerCollection
=
this
.
handlers
[
direction
][
priority
];
if
(
proto
&&
handlerCollection
.
has
(
bufferProto
))
{
if
(
proto
&&
handlerCollection
.
has
(
bufferProto
))
{
let
struct
=
this
.
structs
.
get
(
this
.
proto_structs
[
direction
][
proto
]);
for
(
const
handler
of
handlerCollection
.
get
(
bufferProto
))
{
for
(
const
handler
of
handlerCollection
.
get
(
bufferProto
))
{
let
info
=
null
;
const
protoCls
=
this
.
getProtoClass
(
bufferProto
,
direction
);
if
(
struct
)
{
const
info
=
protoCls
struct
.
_setBuff
(
buffer
);
?
(
0
,
ygopro_msg_struct_compat_1
.
applyYGOProMsgStructCompat
)(
new
protoCls
().
fromPayload
(
buffer
))
info
=
underscore_1
.
default
.
clone
(
struct
.
fields
);
:
null
;
}
cancel
=
await
handler
.
handle
(
buffer
,
info
,
datas
,
params
);
cancel
=
await
handler
.
handle
(
buffer
,
info
,
datas
,
params
);
if
(
cancel
)
{
if
(
cancel
)
{
if
(
Buffer
.
isBuffer
(
cancel
))
{
if
(
Buffer
.
isBuffer
(
cancel
))
{
...
...
YGOProMessages.ts
View file @
ec34713f
import
{
Struct
}
from
"
./struct
"
;
import
_
from
"
underscore
"
;
import
_
from
"
underscore
"
;
import
structs_declaration
from
"
./data/structs.json
"
;
import
typedefs
from
"
./data/typedefs.json
"
;
import
proto_structs
from
"
./data/proto_structs.json
"
;
import
loadConstants
from
"
./load-constants
"
;
import
loadConstants
from
"
./load-constants
"
;
import
net
from
"
net
"
;
import
net
from
"
net
"
;
import
{
YGOProCtos
,
YGOProCtosBase
,
YGOProStoc
,
YGOProStocBase
}
from
"
ygopro-msg-encode
"
;
import
{
applyYGOProMsgStructCompat
,
fromPartialCompat
}
from
"
./ygopro-msg-struct-compat
"
;
import
legacyProtoStructs
from
"
./data/proto_structs.json
"
;
class
Handler
{
class
Handler
{
private
handler
:
(
buffer
:
Buffer
,
info
:
any
,
datas
:
Buffer
[],
params
:
any
)
=>
Promise
<
boolean
|
string
|
Buffer
>
;
constructor
(
synchronous
:
boolean
;
private
handler
:
(
buffer
:
Buffer
,
info
:
YGOProStocBase
|
YGOProCtosBase
,
datas
:
Buffer
[],
params
:
any
)
=>
Promise
<
boolean
|
string
|
Buffer
>
,
constructor
(
handler
:
(
buffer
:
Buffer
,
info
:
any
,
datas
:
Buffer
[],
params
:
any
)
=>
Promise
<
boolean
|
string
|
Buffer
>
,
synchronous
:
boolean
)
{
public
synchronous
:
boolean
this
.
handler
=
handler
;
)
{}
this
.
synchronous
=
synchronous
||
false
;
async
handle
(
buffer
:
Buffer
,
info
:
YGOProStocBase
|
YGOProCtosBase
,
datas
:
Buffer
[],
params
:
any
):
Promise
<
boolean
|
string
|
Buffer
>
{
}
async
handle
(
buffer
:
Buffer
,
info
:
any
,
datas
:
Buffer
[],
params
:
any
):
Promise
<
boolean
|
string
|
Buffer
>
{
if
(
this
.
synchronous
)
{
if
(
this
.
synchronous
)
{
return
await
this
.
handler
(
buffer
,
info
,
datas
,
params
);
return
await
this
.
handler
(
buffer
,
info
,
datas
,
params
);
}
else
{
}
else
{
...
@@ -31,12 +28,21 @@ interface HandlerList {
...
@@ -31,12 +28,21 @@ interface HandlerList {
CTOS
:
Map
<
number
,
Handler
[]
>
[];
CTOS
:
Map
<
number
,
Handler
[]
>
[];
}
}
interface
DirectionBase
{
STOC
:
typeof
YGOProStocBase
;
CTOS
:
typeof
YGOProCtosBase
;
}
type
DirectionToBase
<
T
>
=
T
extends
`
${
infer
K
extends
keyof
DirectionBase
}
_
${
string
}
`
?
DirectionBase
[
K
]
:
DirectionBase
[
keyof
DirectionBase
];
interface
DirectionAndProto
{
interface
DirectionAndProto
{
direction
:
string
;
direction
:
keyof
HandlerList
;
proto
:
string
;
proto
:
string
;
}
}
export
interface
Feedback
{
export
interface
Feedback
{
type
:
string
;
type
:
string
;
message
:
string
;
message
:
string
;
}
}
...
@@ -64,18 +70,48 @@ export interface Constants {
...
@@ -64,18 +70,48 @@ export interface Constants {
MSG
:
Record
<
string
,
string
>
;
MSG
:
Record
<
string
,
string
>
;
}
}
export
class
YGOProMessagesHelper
{
export
class
LegacyStructInst
{
buffer
:
Buffer
;
constructor
(
private
cls
?:
typeof
YGOProCtosBase
|
typeof
YGOProStocBase
)
{}
handlers
:
HandlerList
;
_setBuff
(
buff
:
Buffer
)
{
structs
:
Map
<
string
,
Struct
>
;
this
.
buffer
=
buff
;
structs_declaration
:
Record
<
string
,
Struct
>
;
}
typedefs
:
Record
<
string
,
string
>
;
proto_structs
:
Record
<
'
CTOS
'
|
'
STOC
'
,
Record
<
string
,
string
>>
;
constants
:
Constants
;
singleHandleLimit
:
number
;
constructor
(
singleHandleLimit
?:
number
)
{
set
(
field
:
string
,
value
:
any
)
{
this
.
handlers
=
{
if
(
!
this
.
buffer
||
!
this
.
cls
)
return
;
const
inst
=
applyYGOProMsgStructCompat
(
new
this
.
cls
().
fromPayload
(
this
.
buffer
));
inst
[
field
]
=
value
;
const
parsed
=
Buffer
.
from
(
inst
.
toPayload
());
if
(
parsed
.
length
>=
this
.
buffer
.
length
)
{
// slice it down
parsed
.
copy
(
this
.
buffer
,
0
,
0
,
this
.
buffer
.
length
);
}
else
{
// copy a small part only
parsed
.
copy
(
this
.
buffer
,
0
,
0
,
parsed
.
length
);
}
}
}
export
class
LegacyStruct
{
private
protoClasses
=
new
Map
<
string
,
typeof
YGOProCtosBase
|
typeof
YGOProStocBase
>
();
constructor
(
private
helper
:
YGOProMessagesHelper
)
{
for
(
const
[
direction
,
list
]
of
Object
.
entries
(
legacyProtoStructs
))
{
for
(
const
[
protoStr
,
structName
]
of
Object
.
entries
(
list
))
{
if
(
!
structName
)
continue
;
this
.
protoClasses
.
set
(
structName
,
this
.
helper
.
getProtoClass
(
protoStr
,
direction
as
keyof
HandlerList
));
}
}
}
get
(
structName
:
string
)
{
return
new
LegacyStructInst
(
this
.
protoClasses
.
get
(
structName
));
}
}
export
class
YGOProMessagesHelper
{
handlers
:
HandlerList
=
{
STOC
:
[
new
Map
(),
STOC
:
[
new
Map
(),
new
Map
(),
new
Map
(),
new
Map
(),
new
Map
(),
...
@@ -88,56 +124,12 @@ export class YGOProMessagesHelper {
...
@@ -88,56 +124,12 @@ export class YGOProMessagesHelper {
new
Map
(),
new
Map
(),
new
Map
(),
new
Map
(),
]
]
}
};
this
.
initDatas
();
constants
=
loadConstants
();
this
.
initStructs
();
if
(
singleHandleLimit
)
{
this
.
singleHandleLimit
=
singleHandleLimit
;
}
else
{
this
.
singleHandleLimit
=
1000
;
}
}
initDatas
()
{
constructor
(
public
singleHandleLimit
=
1000
)
{}
this
.
structs_declaration
=
structs_declaration
;
this
.
typedefs
=
typedefs
;
this
.
proto_structs
=
proto_structs
;
this
.
constants
=
loadConstants
();
}
initStructs
()
{
structs
=
new
LegacyStruct
(
this
);
this
.
structs
=
new
Map
();
for
(
let
name
in
this
.
structs_declaration
)
{
const
declaration
=
this
.
structs_declaration
[
name
];
let
result
=
Struct
();
for
(
let
field
of
declaration
)
{
if
(
field
.
encoding
)
{
switch
(
field
.
encoding
)
{
case
"
UTF-16LE
"
:
result
.
chars
(
field
.
name
,
field
.
length
*
2
,
field
.
encoding
);
break
;
default
:
throw
`unsupported encoding:
${
field
.
encoding
}
`
;
}
}
else
{
let
type
=
field
.
type
;
if
(
this
.
typedefs
[
type
])
{
type
=
this
.
typedefs
[
type
];
}
if
(
field
.
length
)
{
result
.
array
(
field
.
name
,
field
.
length
,
type
);
//不支持结构体
}
else
{
if
(
this
.
structs
.
has
(
type
))
{
result
.
struct
(
field
.
name
,
this
.
structs
.
get
(
type
));
}
else
{
result
[
type
](
field
.
name
);
}
}
}
}
this
.
structs
.
set
(
name
,
result
);
}
}
getDirectionAndProto
(
protoStr
:
string
):
DirectionAndProto
{
getDirectionAndProto
(
protoStr
:
string
):
DirectionAndProto
{
const
protoStrMatch
=
protoStr
.
match
(
/^
(
STOC|CTOS
)
_
([
_A-Z
]
+
)
$/
);
const
protoStrMatch
=
protoStr
.
match
(
/^
(
STOC|CTOS
)
_
([
_A-Z
]
+
)
$/
);
...
@@ -145,13 +137,12 @@ export class YGOProMessagesHelper {
...
@@ -145,13 +137,12 @@ export class YGOProMessagesHelper {
throw
`Invalid proto string:
${
protoStr
}
`
throw
`Invalid proto string:
${
protoStr
}
`
}
}
return
{
return
{
direction
:
protoStrMatch
[
1
].
toUpperCase
(),
direction
:
protoStrMatch
[
1
].
toUpperCase
()
as
keyof
HandlerList
,
proto
:
protoStrMatch
[
2
].
toUpperCase
()
proto
:
protoStrMatch
[
2
].
toUpperCase
()
}
}
}
}
translateProto
(
proto
:
string
|
number
,
direction
:
keyof
HandlerList
):
number
{
translateProto
(
proto
:
string
|
number
,
direction
:
string
):
number
{
const
directionProtoList
=
this
.
constants
[
direction
];
const
directionProtoList
=
this
.
constants
[
direction
];
if
(
typeof
proto
!==
"
string
"
)
{
if
(
typeof
proto
!==
"
string
"
)
{
return
proto
;
return
proto
;
...
@@ -165,25 +156,43 @@ export class YGOProMessagesHelper {
...
@@ -165,25 +156,43 @@ export class YGOProMessagesHelper {
return
parseInt
(
translatedProto
);
return
parseInt
(
translatedProto
);
}
}
getProtoClass
<
T
extends
string
|
number
>
(
proto
:
T
,
direction
:
keyof
HandlerList
):
DirectionToBase
<
T
>
{
const
identifier
=
typeof
proto
===
'
number
'
?
proto
:
this
.
translateProto
(
proto
,
direction
);
const
registry
=
direction
===
'
CTOS
'
?
YGOProCtos
:
direction
===
'
STOC
'
?
YGOProStoc
:
null
;
if
(
!
registry
)
{
throw
`Invalid direction:
${
direction
}
`
;
}
return
registry
.
get
(
identifier
)
as
DirectionToBase
<
T
>
;
}
classToProtoStr
(
cls
:
typeof
YGOProCtosBase
|
typeof
YGOProStocBase
):
string
{
const
registry
=
cls
.
prototype
instanceof
YGOProCtosBase
?
YGOProCtos
:
cls
.
prototype
instanceof
YGOProStocBase
?
YGOProStoc
:
null
;
if
(
!
registry
)
{
throw
`Invalid class:
${
cls
.
name
}
`
;
}
const
identifier
=
cls
.
identifier
;
const
direction
=
cls
.
prototype
instanceof
YGOProCtosBase
?
'
CTOS
'
:
'
STOC
'
;
return
`
${
direction
}
_
${
this
.
constants
[
direction
][
identifier
]}
`
;
}
prepareMessage
(
protostr
:
string
,
info
?:
string
|
Buffer
|
any
):
Buffer
{
prepareMessage
(
protostr
:
string
,
info
?:
string
|
Buffer
|
any
):
Buffer
{
const
{
const
{
direction
,
direction
,
proto
proto
}
=
this
.
getDirectionAndProto
(
protostr
);
}
=
this
.
getDirectionAndProto
(
protostr
);
const
translatedProto
=
this
.
translateProto
(
proto
,
direction
);
let
buffer
:
Buffer
;
let
buffer
:
Buffer
;
//console.log(proto, this.proto_structs[direction][proto]);
//const directionProtoList = this.constants[direction];
if
(
typeof
info
===
'
undefined
'
)
{
if
(
typeof
info
===
'
undefined
'
)
{
buffer
=
null
;
buffer
=
null
;
}
else
if
(
Buffer
.
isBuffer
(
info
))
{
}
else
if
(
Buffer
.
isBuffer
(
info
))
{
buffer
=
info
;
buffer
=
info
;
}
else
{
}
else
{
let
struct
=
this
.
structs
.
get
(
this
.
proto_structs
[
direction
][
proto
]);
const
protoCls
=
this
.
getProtoClass
(
translatedProto
,
direction
);
struct
.
allocate
();
if
(
!
protoCls
)
{
struct
.
set
(
info
);
throw
`No proto class for
${
protostr
}
`
;
buffer
=
struct
.
buffer
();
}
buffer
=
Buffer
.
from
(
fromPartialCompat
(
protoCls
,
info
).
toPayload
());
}
}
const
translatedProto
=
this
.
translateProto
(
proto
,
direction
);
let
sendBuffer
=
Buffer
.
allocUnsafe
(
3
+
(
buffer
?
buffer
.
length
:
0
));
let
sendBuffer
=
Buffer
.
allocUnsafe
(
3
+
(
buffer
?
buffer
.
length
:
0
));
if
(
buffer
)
{
if
(
buffer
)
{
sendBuffer
.
writeUInt16LE
(
buffer
.
length
+
1
,
0
);
sendBuffer
.
writeUInt16LE
(
buffer
.
length
+
1
,
0
);
...
@@ -214,7 +223,7 @@ export class YGOProMessagesHelper {
...
@@ -214,7 +223,7 @@ export class YGOProMessagesHelper {
return
this
.
send
(
socket
,
sendBuffer
);
return
this
.
send
(
socket
,
sendBuffer
);
}
}
addHandler
(
protostr
:
string
,
handler
:
(
buffer
:
Buffer
,
info
:
any
,
datas
:
Buffer
[],
params
:
any
)
=>
Promise
<
boolean
|
string
>
,
synchronous
:
boolean
,
priority
:
number
)
{
addHandler
<
T
extends
string
>
(
protostr
:
T
,
handler
:
(
buffer
:
Buffer
,
info
:
InstanceType
<
DirectionToBase
<
T
>>
,
datas
:
Buffer
[],
params
:
any
)
=>
Promise
<
boolean
|
string
>
,
synchronous
:
boolean
,
priority
:
number
)
{
if
(
priority
<
0
||
priority
>
4
)
{
if
(
priority
<
0
||
priority
>
4
)
{
throw
"
Invalid priority:
"
+
priority
;
throw
"
Invalid priority:
"
+
priority
;
}
}
...
@@ -232,7 +241,7 @@ export class YGOProMessagesHelper {
...
@@ -232,7 +241,7 @@ export class YGOProMessagesHelper {
handlerCollection
.
get
(
translatedProto
).
push
(
handlerObj
);
handlerCollection
.
get
(
translatedProto
).
push
(
handlerObj
);
}
}
async
handleBuffer
(
messageBuffer
:
Buffer
,
direction
:
string
,
protoFilter
?:
string
[],
params
?:
any
,
preconnect
=
false
):
Promise
<
HandleResult
>
{
async
handleBuffer
(
messageBuffer
:
Buffer
,
direction
:
keyof
HandlerList
,
protoFilter
?:
string
[],
params
?:
any
,
preconnect
=
false
):
Promise
<
HandleResult
>
{
let
feedback
:
Feedback
=
null
;
let
feedback
:
Feedback
=
null
;
let
messageLength
=
0
;
let
messageLength
=
0
;
let
bufferProto
=
0
;
let
bufferProto
=
0
;
...
@@ -281,13 +290,11 @@ export class YGOProMessagesHelper {
...
@@ -281,13 +290,11 @@ export class YGOProMessagesHelper {
}
}
const
handlerCollection
:
Map
<
number
,
Handler
[]
>
=
this
.
handlers
[
direction
][
priority
];
const
handlerCollection
:
Map
<
number
,
Handler
[]
>
=
this
.
handlers
[
direction
][
priority
];
if
(
proto
&&
handlerCollection
.
has
(
bufferProto
))
{
if
(
proto
&&
handlerCollection
.
has
(
bufferProto
))
{
let
struct
=
this
.
structs
.
get
(
this
.
proto_structs
[
direction
][
proto
]);
for
(
const
handler
of
handlerCollection
.
get
(
bufferProto
))
{
for
(
const
handler
of
handlerCollection
.
get
(
bufferProto
))
{
let
info
=
null
;
const
protoCls
=
this
.
getProtoClass
(
bufferProto
,
direction
);
if
(
struct
)
{
const
info
=
protoCls
struct
.
_setBuff
(
buffer
);
?
applyYGOProMsgStructCompat
(
new
protoCls
().
fromPayload
(
buffer
))
info
=
_
.
clone
(
struct
.
fields
);
:
null
;
}
cancel
=
await
handler
.
handle
(
buffer
,
info
,
datas
,
params
);
cancel
=
await
handler
.
handle
(
buffer
,
info
,
datas
,
params
);
if
(
cancel
)
{
if
(
cancel
)
{
if
(
Buffer
.
isBuffer
(
cancel
))
{
if
(
Buffer
.
isBuffer
(
cancel
))
{
...
...
data/structs.json
deleted
100644 → 0
View file @
72fc9542
{
"HostInfo"
:
[
{
"name"
:
"lflist"
,
"type"
:
"unsigned int"
},
{
"name"
:
"rule"
,
"type"
:
"unsigned char"
},
{
"name"
:
"mode"
,
"type"
:
"unsigned char"
},
{
"name"
:
"duel_rule"
,
"type"
:
"unsigned char"
},
{
"name"
:
"no_check_deck"
,
"type"
:
"bool"
},
{
"name"
:
"no_shuffle_deck"
,
"type"
:
"bool"
},
{
"name"
:
"start_lp"
,
"type"
:
"unsigned int"
},
{
"name"
:
"start_hand"
,
"type"
:
"unsigned char"
},
{
"name"
:
"draw_count"
,
"type"
:
"unsigned char"
},
{
"name"
:
"time_limit"
,
"type"
:
"unsigned short"
}
],
"HostPacket"
:
[
{
"name"
:
"identifier"
,
"type"
:
"unsigned short"
},
{
"name"
:
"version"
,
"type"
:
"unsigned short"
},
{
"name"
:
"port"
,
"type"
:
"unsigned short"
},
{
"name"
:
"ipaddr"
,
"type"
:
"unsigned int"
},
{
"name"
:
"name"
,
"type"
:
"unsigned short"
,
"length"
:
20
,
"encoding"
:
"UTF-16LE"
},
{
"name"
:
"host"
,
"type"
:
"HostInfo"
}
],
"HostRequest"
:
[
{
"name"
:
"identifier"
,
"type"
:
"unsigned short"
}
],
"CTOS_HandResult"
:
[
{
"name"
:
"res"
,
"type"
:
"unsigned char"
}
],
"CTOS_TPResult"
:
[
{
"name"
:
"res"
,
"type"
:
"unsigned char"
}
],
"CTOS_PlayerInfo"
:
[
{
"name"
:
"name"
,
"type"
:
"unsigned short"
,
"length"
:
20
,
"encoding"
:
"UTF-16LE"
}
],
"CTOS_CreateGame"
:
[
{
"name"
:
"info"
,
"type"
:
"HostInfo"
},
{
"name"
:
"name"
,
"type"
:
"unsigned short"
,
"length"
:
20
,
"encoding"
:
"UTF-16LE"
},
{
"name"
:
"pass"
,
"type"
:
"unsigned short"
,
"length"
:
20
,
"encoding"
:
"UTF-16LE"
}
],
"CTOS_JoinGame"
:
[
{
"name"
:
"version"
,
"type"
:
"unsigned short"
},
{
"name"
:
"align"
,
"type"
:
"unsigned short"
},
{
"name"
:
"gameid"
,
"type"
:
"unsigned int"
},
{
"name"
:
"pass"
,
"type"
:
"unsigned short"
,
"length"
:
20
,
"encoding"
:
"UTF-16LE"
}
],
"CTOS_ExternalAddress"
:
[
{
"name"
:
"real_ip"
,
"type"
:
"unsigned int"
},
{
"name"
:
"hostname"
,
"type"
:
"unsigned short"
,
"length"
:
"256"
,
"encoding"
:
"UTF-16LE"
}
],
"CTOS_Kick"
:
[
{
"name"
:
"pos"
,
"type"
:
"unsigned char"
}
],
"STOC_ErrorMsg"
:
[
{
"name"
:
"msg"
,
"type"
:
"unsigned char"
},
{
"name"
:
"align1"
,
"type"
:
"unsigned char"
},
{
"name"
:
"align2"
,
"type"
:
"unsigned char"
},
{
"name"
:
"align3"
,
"type"
:
"unsigned char"
},
{
"name"
:
"code"
,
"type"
:
"unsigned int"
}
],
"STOC_HandResult"
:
[
{
"name"
:
"res1"
,
"type"
:
"unsigned char"
},
{
"name"
:
"res2"
,
"type"
:
"unsigned char"
}
],
"STOC_CreateGame"
:
[
{
"name"
:
"gameid"
,
"type"
:
"unsigned int"
}
],
"STOC_JoinGame"
:
[
{
"name"
:
"info"
,
"type"
:
"HostInfo"
}
],
"STOC_TypeChange"
:
[
{
"name"
:
"type"
,
"type"
:
"unsigned char"
}
],
"STOC_ExitGame"
:
[
{
"name"
:
"pos"
,
"type"
:
"unsigned char"
}
],
"STOC_TimeLimit"
:
[
{
"name"
:
"player"
,
"type"
:
"unsigned char"
},
{
"name"
:
"left_time"
,
"type"
:
"unsigned short"
}
],
"STOC_Chat"
:
[
{
"name"
:
"player"
,
"type"
:
"unsigned short"
},
{
"name"
:
"msg"
,
"type"
:
"unsigned short"
,
"length"
:
255
,
"encoding"
:
"UTF-16LE"
}
],
"STOC_HS_PlayerEnter"
:
[
{
"name"
:
"name"
,
"type"
:
"unsigned short"
,
"length"
:
20
,
"encoding"
:
"UTF-16LE"
},
{
"name"
:
"pos"
,
"type"
:
"unsigned char"
},
{
"name"
:
"padding"
,
"type"
:
"unsigned char"
}
],
"STOC_HS_PlayerChange"
:
[
{
"name"
:
"status"
,
"type"
:
"unsigned char"
}
],
"STOC_HS_WatchChange"
:
[
{
"name"
:
"watch_count"
,
"type"
:
"unsigned short"
}
],
"GameMsg_Hint_Card_only"
:
[
{
"name"
:
"curmsg"
,
"type"
:
"word8Ule"
},
{
"name"
:
"type"
,
"type"
:
"word8"
},
{
"name"
:
"player"
,
"type"
:
"word8"
},
{
"name"
:
"data"
,
"type"
:
"word32Ule"
}
],
"deck"
:
[
{
"name"
:
"mainc"
,
"type"
:
"unsigned int"
},
{
"name"
:
"sidec"
,
"type"
:
"unsigned int"
},
{
"name"
:
"deckbuf"
,
"type"
:
"unsigned int"
,
"length"
:
90
}
],
"chat"
:
[
{
"name"
:
"msg"
,
"type"
:
"unsigned short"
,
"length"
:
"255"
,
"encoding"
:
"UTF-16LE"
}
],
"STOC_DeckCount"
:
[
{
"name"
:
"mainc_s"
,
"type"
:
"unsigned short"
},
{
"name"
:
"sidec_s"
,
"type"
:
"unsigned short"
},
{
"name"
:
"extrac_s"
,
"type"
:
"unsigned short"
},
{
"name"
:
"mainc_o"
,
"type"
:
"unsigned short"
},
{
"name"
:
"sidec_o"
,
"type"
:
"unsigned short"
},
{
"name"
:
"extrac_o"
,
"type"
:
"unsigned short"
}
]
}
data/typedefs.json
deleted
100644 → 0
View file @
72fc9542
{
"unsigned int"
:
"word32Ule"
,
"unsigned short"
:
"word16Ule"
,
"unsigned char"
:
"word8"
,
"bool"
:
"bool2"
}
\ No newline at end of file
load-constants.js
View file @
ec34713f
...
@@ -136,3 +136,6 @@ const loadConstants = () => {
...
@@ -136,3 +136,6 @@ const loadConstants = () => {
};
};
exports
.
loadConstants
=
loadConstants
;
exports
.
loadConstants
=
loadConstants
;
exports
.
default
=
exports
.
loadConstants
;
exports
.
default
=
exports
.
loadConstants
;
if
(
require
.
main
===
module
)
{
console
.
log
(
JSON
.
stringify
((
0
,
exports
.
loadConstants
)(),
null
,
2
));
}
load-constants.ts
View file @
ec34713f
...
@@ -171,3 +171,7 @@ export const loadConstants = () => {
...
@@ -171,3 +171,7 @@ export const loadConstants = () => {
};
};
export
default
loadConstants
;
export
default
loadConstants
;
if
(
require
.
main
===
module
)
{
console
.
log
(
JSON
.
stringify
(
loadConstants
(),
null
,
2
));
}
struct.js
deleted
100644 → 0
View file @
72fc9542
// a special version of node-struct by xdenser
// https://github.com/xdenser/node-struct/tree/f843487d6768cd0bf20c2ce7803dde2d92df5694
function
byteField
(
p
,
offset
)
{
this
.
length
=
1
;
this
.
get
=
function
()
{
return
p
.
buf
[
offset
];
}
this
.
set
=
function
(
val
)
{
p
.
buf
[
offset
]
=
val
;
}
}
function
boolField
(
p
,
offset
,
length
)
{
this
.
length
=
length
;
this
.
get
=
function
()
{
return
(
p
.
buf
[
offset
]
>
0
);
}
this
.
set
=
function
(
val
)
{
p
.
buf
[
offset
]
=
val
?
1
:
0
;
}
}
function
intField
(
p
,
offset
,
length
,
le
,
signed
)
{
this
.
length
=
length
;
function
bec
(
cb
)
{
for
(
var
i
=
0
;
i
<
length
;
i
++
)
cb
(
i
,
length
-
i
-
1
);
}
function
lec
(
cb
)
{
for
(
var
i
=
0
;
i
<
length
;
i
++
)
cb
(
i
,
i
);
}
function
getUVal
(
bor
)
{
var
val
=
0
;
bor
(
function
(
i
,
o
)
{
val
+=
Math
.
pow
(
256
,
o
)
*
p
.
buf
[
offset
+
i
];
})
return
val
;
}
function
getSVal
(
bor
)
{
var
val
=
getUVal
(
bor
);
if
((
p
.
buf
[
offset
+
(
le
?
(
length
-
1
)
:
0
)]
&
0x80
)
==
0x80
)
{
val
-=
Math
.
pow
(
256
,
length
);
}
return
val
;
}
function
setVal
(
bor
,
val
)
{
bor
(
function
(
i
,
o
)
{
p
.
buf
[
offset
+
i
]
=
Math
.
floor
(
val
/
Math
.
pow
(
256
,
o
))
&
0xff
;
});
}
this
.
get
=
function
()
{
var
bor
=
le
?
lec
:
bec
;
return
(
signed
?
getSVal
(
bor
)
:
getUVal
(
bor
));
}
this
.
set
=
function
(
val
)
{
var
bor
=
le
?
lec
:
bec
;
setVal
(
bor
,
val
);
}
}
function
charField
(
p
,
offset
,
length
,
encoding
)
{
this
.
length
=
length
;
this
.
encoding
=
encoding
;
this
.
get
=
function
()
{
var
result
=
p
.
buf
.
toString
(
this
.
encoding
,
offset
,
offset
+
length
);
var
strlen
=
result
.
indexOf
(
"
\
0
"
);
if
(
strlen
==
-
1
)
{
return
result
;
}
else
{
return
result
.
slice
(
0
,
strlen
);
}
}
this
.
set
=
function
(
val
)
{
val
+=
"
\
0
"
;
if
(
val
.
length
>
length
)
val
=
val
.
substring
(
0
,
length
);
p
.
buf
.
write
(
val
,
offset
,
this
.
encoding
);
}
}
function
structField
(
p
,
offset
,
struct
)
{
this
.
length
=
struct
.
length
();
this
.
get
=
function
()
{
return
struct
;
}
this
.
set
=
function
(
val
)
{
struct
.
set
(
val
);
}
this
.
allocate
=
function
()
{
struct
.
_setBuff
(
p
.
buf
.
slice
(
offset
,
offset
+
struct
.
length
()));
}
}
function
arrayField
(
p
,
offset
,
len
,
type
)
{
var
as
=
Struct
();
var
args
=
[].
slice
.
call
(
arguments
,
4
);
args
.
unshift
(
0
);
for
(
var
i
=
0
;
i
<
len
;
i
++
)
{
if
(
type
instanceof
Struct
)
{
as
.
struct
(
i
,
type
.
clone
());
}
else
if
(
type
in
as
)
{
args
[
0
]
=
i
;
as
[
type
].
apply
(
as
,
args
);
}
}
this
.
length
=
as
.
length
();
this
.
allocate
=
function
()
{
as
.
_setBuff
(
p
.
buf
.
slice
(
offset
,
offset
+
as
.
length
()));
}
this
.
get
=
function
()
{
return
as
;
}
this
.
set
=
function
(
val
)
{
as
.
set
(
val
);
}
}
function
Struct
()
{
if
(
!
(
this
instanceof
Struct
))
return
new
Struct
;
var
priv
=
{
buf
:
{},
allocated
:
false
,
len
:
0
,
fields
:
{},
closures
:
[]
},
self
=
this
;
function
checkAllocated
()
{
if
(
priv
.
allocated
)
throw
new
Error
(
'
Cant change struct after allocation
'
);
}
this
.
word8
=
function
(
key
)
{
checkAllocated
();
priv
.
closures
.
push
(
function
(
p
)
{
p
.
fields
[
key
]
=
new
byteField
(
p
,
p
.
len
);
p
.
len
++
;
});
return
this
;
};
// Create handlers for various Bool Field Variants
[
1
,
2
,
3
,
4
].
forEach
(
function
(
n
)
{
self
[
'
bool
'
+
(
n
==
1
?
''
:
n
)]
=
function
(
key
)
{
checkAllocated
();
priv
.
closures
.
push
(
function
(
p
)
{
p
.
fields
[
key
]
=
new
boolField
(
p
,
p
.
len
,
n
);
p
.
len
+=
n
;
});
return
this
;
}
});
// Create handlers for various Integer Field Variants
[
1
,
2
,
3
,
4
,
6
,
8
].
forEach
(
function
(
n
)
{
[
true
,
false
].
forEach
(
function
(
le
)
{
[
true
,
false
].
forEach
(
function
(
signed
)
{
var
name
=
'
word
'
+
(
n
*
8
)
+
(
signed
?
'
S
'
:
'
U
'
)
+
(
le
?
'
le
'
:
'
be
'
);
self
[
name
]
=
function
(
key
)
{
checkAllocated
();
priv
.
closures
.
push
(
function
(
p
)
{
p
.
fields
[
key
]
=
new
intField
(
p
,
p
.
len
,
n
,
le
,
signed
);
p
.
len
+=
n
;
});
return
this
;
};
});
});
});
this
.
chars
=
function
(
key
,
length
,
encoding
)
{
checkAllocated
();
priv
.
closures
.
push
(
function
(
p
)
{
p
.
fields
[
key
]
=
new
charField
(
p
,
p
.
len
,
length
,
encoding
||
'
ascii
'
);
p
.
len
+=
length
;
});
return
this
;
}
this
.
struct
=
function
(
key
,
struct
)
{
checkAllocated
();
priv
.
closures
.
push
(
function
(
p
)
{
p
.
fields
[
key
]
=
new
structField
(
p
,
p
.
len
,
struct
.
clone
());
p
.
len
+=
p
.
fields
[
key
].
length
;
});
return
this
;
}
function
construct
(
constructor
,
args
)
{
function
F
()
{
return
constructor
.
apply
(
this
,
args
);
}
F
.
prototype
=
constructor
.
prototype
;
return
new
F
();
}
this
.
array
=
function
(
key
,
length
,
type
)
{
checkAllocated
();
var
args
=
[].
slice
.
call
(
arguments
,
1
);
args
.
unshift
(
null
);
args
.
unshift
(
null
);
priv
.
closures
.
push
(
function
(
p
)
{
args
[
0
]
=
p
;
args
[
1
]
=
p
.
len
;
p
.
fields
[
key
]
=
construct
(
arrayField
,
args
);
p
.
len
+=
p
.
fields
[
key
].
length
;
});
return
this
;
}
var
beenHere
=
false
;
function
applyClosures
(
p
)
{
if
(
beenHere
)
return
;
p
.
closures
.
forEach
(
function
(
el
)
{
el
(
p
);
});
beenHere
=
true
;
}
function
allocateFields
()
{
for
(
var
key
in
priv
.
fields
)
{
if
(
'
allocate
'
in
priv
.
fields
[
key
])
priv
.
fields
[
key
].
allocate
();
}
}
this
.
_setBuff
=
function
(
buff
)
{
priv
.
buf
=
buff
;
applyClosures
(
priv
);
allocateFields
();
priv
.
allocated
=
true
;
}
this
.
allocate
=
function
()
{
applyClosures
(
priv
);
priv
.
buf
=
Buffer
.
alloc
(
priv
.
len
);
allocateFields
();
priv
.
allocated
=
true
;
return
this
;
}
this
.
_getPriv
=
function
()
{
return
priv
;
}
this
.
clone
=
function
()
{
var
c
=
new
Struct
;
var
p
=
c
.
_getPriv
();
p
.
closures
=
priv
.
closures
;
return
c
;
}
this
.
length
=
function
()
{
applyClosures
(
priv
);
return
priv
.
len
;
}
this
.
get
=
function
(
key
)
{
if
(
key
in
priv
.
fields
)
{
return
priv
.
fields
[
key
].
get
();
}
else
throw
new
Error
(
'
Can not find field
'
+
key
);
}
this
.
set
=
function
(
key
,
val
)
{
if
(
arguments
.
length
==
2
)
{
if
(
key
in
priv
.
fields
)
{
priv
.
fields
[
key
].
set
(
val
);
}
else
throw
new
Error
(
'
Can not find field
'
+
key
);
}
else
if
(
Buffer
.
isBuffer
(
key
))
{
this
.
_setBuff
(
key
);
}
else
{
for
(
var
k
in
key
)
{
this
.
set
(
k
,
key
[
k
]);
}
}
}
this
.
buffer
=
function
()
{
return
priv
.
buf
;
}
function
getFields
()
{
var
fields
=
{};
Object
.
keys
(
priv
.
fields
).
forEach
(
function
(
key
)
{
Object
.
defineProperty
(
fields
,
key
,
{
get
:
function
()
{
var
res
=
self
.
get
(
key
);
if
(
res
instanceof
Struct
)
return
res
.
fields
;
else
return
res
;
},
set
:
function
(
newVal
)
{
self
.
set
(
key
,
newVal
);
},
enumerable
:
true
});
});
return
fields
;
};
var
_fields
;
Object
.
defineProperty
(
this
,
'
fields
'
,
{
get
:
function
()
{
if
(
_fields
)
return
_fields
;
return
(
_fields
=
getFields
());
},
enumerable
:
true
,
configurable
:
true
});
}
exports
.
Struct
=
Struct
;
ygopro-server.coffee
View file @
ec34713f
...
@@ -3383,8 +3383,6 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server, datas)->
...
@@ -3383,8 +3383,6 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server, datas)->
else
else
ygopro
.
stoc_send_chat
(
client
,
"${get_chat_color_default}"
,
ygopro
.
constants
.
COLORS
.
BABYBLUE
)
ygopro
.
stoc_send_chat
(
client
,
"${get_chat_color_default}"
,
ygopro
.
constants
.
COLORS
.
BABYBLUE
)
#when '/test'
# ygopro.stoc_send_hint_card_to_room(room, 2333365)
if
(
msg
.
length
>
100
)
if
(
msg
.
length
>
100
)
log
.
warn
"SPAM WORD"
,
client
.
name
,
client
.
ip
,
msg
log
.
warn
"SPAM WORD"
,
client
.
name
,
client
.
ip
,
msg
client
.
abuse_count
=
client
.
abuse_count
+
2
if
client
.
abuse_count
client
.
abuse_count
=
client
.
abuse_count
+
2
if
client
.
abuse_count
...
...
ygopro-server.js
View file @
ec34713f
...
@@ -4530,8 +4530,6 @@
...
@@ -4530,8 +4530,6 @@
}
}
}
}
}
}
//when '/test'
// ygopro.stoc_send_hint_card_to_room(room, 2333365)
if
(
msg
.
length
>
100
)
{
if
(
msg
.
length
>
100
)
{
log
.
warn
(
"
SPAM WORD
"
,
client
.
name
,
client
.
ip
,
msg
);
log
.
warn
(
"
SPAM WORD
"
,
client
.
name
,
client
.
ip
,
msg
);
if
(
client
.
abuse_count
)
{
if
(
client
.
abuse_count
)
{
...
...
ygopro.coffee
View file @
ec34713f
...
@@ -2,7 +2,6 @@ _ = require 'underscore'
...
@@ -2,7 +2,6 @@ _ = require 'underscore'
_
.
str
=
require
'underscore.string'
_
.
str
=
require
'underscore.string'
_
.
mixin
(
_
.
str
.
exports
())
_
.
mixin
(
_
.
str
.
exports
())
Struct
=
require
(
'./struct.js'
).
Struct
loadJSON
=
require
(
'load-json-file'
).
sync
loadJSON
=
require
(
'load-json-file'
).
sync
@
i18ns
=
loadJSON
'./data/i18n.json'
@
i18ns
=
loadJSON
'./data/i18n.json'
...
@@ -23,9 +22,6 @@ YGOProMessagesHelper = require("./YGOProMessages.js").YGOProMessagesHelper # 为
...
@@ -23,9 +22,6 @@ YGOProMessagesHelper = require("./YGOProMessages.js").YGOProMessagesHelper # 为
@
helper
=
new
YGOProMessagesHelper
(
9000
)
@
helper
=
new
YGOProMessagesHelper
(
9000
)
@
structs
=
@
helper
.
structs
@
structs
=
@
helper
.
structs
@
structs_declaration
=
@
helper
.
structs_declaration
@
typedefs
=
@
helper
.
typedefs
@
proto_structs
=
@
helper
.
proto_structs
@
constants
=
@
helper
.
constants
@
constants
=
@
helper
.
constants
translateHandler
=
(
handler
)
->
translateHandler
=
(
handler
)
->
...
@@ -91,26 +87,6 @@ translateHandler = (handler) ->
...
@@ -91,26 +87,6 @@ translateHandler = (handler) ->
room
.
recordChatMessage
(
msg
,
player
)
room
.
recordChatMessage
(
msg
,
player
)
return
return
@
stoc_send_hint_card_to_room
=
(
room
,
card
)
->
if
!
room
console
.
log
"err stoc_send_hint_card_to_room"
return
for
client
in
room
.
players
@
stoc_send
client
,
'GAME_MSG'
,
{
curmsg
:
2
,
type
:
10
,
player
:
0
,
data
:
card
}
if
client
for
client
in
room
.
watchers
@
stoc_send
client
,
'GAME_MSG'
,
{
curmsg
:
2
,
type
:
10
,
player
:
0
,
data
:
card
}
if
client
return
@
stoc_die
=
(
client
,
msg
)
->
@
stoc_die
=
(
client
,
msg
)
->
await
@
stoc_send_chat
(
client
,
msg
,
@
constants
.
COLORS
.
RED
)
await
@
stoc_send_chat
(
client
,
msg
,
@
constants
.
COLORS
.
RED
)
await
@
stoc_send
client
,
'ERROR_MSG'
,
{
await
@
stoc_send
client
,
'ERROR_MSG'
,
{
...
...
ygopro.js
View file @
ec34713f
// Generated by CoffeeScript 2.7.0
// Generated by CoffeeScript 2.7.0
(
function
()
{
(
function
()
{
var
Struct
,
YGOProMessagesHelper
,
_
,
loadJSON
,
translateHandler
;
var
YGOProMessagesHelper
,
_
,
loadJSON
,
translateHandler
;
_
=
require
(
'
underscore
'
);
_
=
require
(
'
underscore
'
);
...
@@ -8,8 +8,6 @@
...
@@ -8,8 +8,6 @@
_
.
mixin
(
_
.
str
.
exports
());
_
.
mixin
(
_
.
str
.
exports
());
Struct
=
require
(
'
./struct.js
'
).
Struct
;
loadJSON
=
require
(
'
load-json-file
'
).
sync
;
loadJSON
=
require
(
'
load-json-file
'
).
sync
;
this
.
i18ns
=
loadJSON
(
'
./data/i18n.json
'
);
this
.
i18ns
=
loadJSON
(
'
./data/i18n.json
'
);
...
@@ -47,12 +45,6 @@
...
@@ -47,12 +45,6 @@
this
.
structs
=
this
.
helper
.
structs
;
this
.
structs
=
this
.
helper
.
structs
;
this
.
structs_declaration
=
this
.
helper
.
structs_declaration
;
this
.
typedefs
=
this
.
helper
.
typedefs
;
this
.
proto_structs
=
this
.
helper
.
proto_structs
;
this
.
constants
=
this
.
helper
.
constants
;
this
.
constants
=
this
.
helper
.
constants
;
translateHandler
=
function
(
handler
)
{
translateHandler
=
function
(
handler
)
{
...
@@ -153,38 +145,6 @@
...
@@ -153,38 +145,6 @@
room
.
recordChatMessage
(
msg
,
player
);
room
.
recordChatMessage
(
msg
,
player
);
};
};
this
.
stoc_send_hint_card_to_room
=
function
(
room
,
card
)
{
var
client
,
i
,
j
,
len
,
len1
,
ref
,
ref1
;
if
(
!
room
)
{
console
.
log
(
"
err stoc_send_hint_card_to_room
"
);
return
;
}
ref
=
room
.
players
;
for
(
i
=
0
,
len
=
ref
.
length
;
i
<
len
;
i
++
)
{
client
=
ref
[
i
];
if
(
client
)
{
this
.
stoc_send
(
client
,
'
GAME_MSG
'
,
{
curmsg
:
2
,
type
:
10
,
player
:
0
,
data
:
card
});
}
}
ref1
=
room
.
watchers
;
for
(
j
=
0
,
len1
=
ref1
.
length
;
j
<
len1
;
j
++
)
{
client
=
ref1
[
j
];
if
(
client
)
{
this
.
stoc_send
(
client
,
'
GAME_MSG
'
,
{
curmsg
:
2
,
type
:
10
,
player
:
0
,
data
:
card
});
}
}
};
this
.
stoc_die
=
async
function
(
client
,
msg
)
{
this
.
stoc_die
=
async
function
(
client
,
msg
)
{
await
this
.
stoc_send_chat
(
client
,
msg
,
this
.
constants
.
COLORS
.
RED
);
await
this
.
stoc_send_chat
(
client
,
msg
,
this
.
constants
.
COLORS
.
RED
);
if
(
client
)
{
if
(
client
)
{
...
...
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