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
693361fd
Commit
693361fd
authored
Nov 14, 2020
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
random duel ban
parent
c8b15204
Changes
8
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
311 additions
and
183 deletions
+311
-183
.dockerignore
.dockerignore
+1
-0
.gitignore
.gitignore
+1
-0
data-manager/DataManager.js
data-manager/DataManager.js
+58
-0
data-manager/DataManager.ts
data-manager/DataManager.ts
+57
-0
data-manager/entities/RandomDuelBan.js
data-manager/entities/RandomDuelBan.js
+49
-0
data-manager/entities/RandomDuelBan.ts
data-manager/entities/RandomDuelBan.ts
+28
-0
ygopro-server.coffee
ygopro-server.coffee
+39
-78
ygopro-server.js
ygopro-server.js
+78
-105
No files found.
.dockerignore
View file @
693361fd
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
jsconfig.json
jsconfig.json
coffeelint.json
coffeelint.json
.vscode/
.vscode/
.idea
password.json
password.json
config.*.json
config.*.json
...
...
.gitignore
View file @
693361fd
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
jsconfig.json
jsconfig.json
coffeelint.json
coffeelint.json
.vscode/
.vscode/
.idea
password.json
password.json
config.*.json
config.*.json
...
...
data-manager/DataManager.js
View file @
693361fd
...
@@ -9,6 +9,8 @@ const typeorm_1 = require("typeorm");
...
@@ -9,6 +9,8 @@ const typeorm_1 = require("typeorm");
const
CloudReplay_1
=
require
(
"
./entities/CloudReplay
"
);
const
CloudReplay_1
=
require
(
"
./entities/CloudReplay
"
);
const
CloudReplayPlayer_1
=
require
(
"
./entities/CloudReplayPlayer
"
);
const
CloudReplayPlayer_1
=
require
(
"
./entities/CloudReplayPlayer
"
);
const
Ban_1
=
require
(
"
./entities/Ban
"
);
const
Ban_1
=
require
(
"
./entities/Ban
"
);
const
RandomDuelBan_1
=
require
(
"
./entities/RandomDuelBan
"
);
const
underscore_1
=
__importDefault
(
require
(
"
underscore
"
));
class
DataManager
{
class
DataManager
{
constructor
(
config
,
log
)
{
constructor
(
config
,
log
)
{
this
.
config
=
config
;
this
.
config
=
config
;
...
@@ -125,6 +127,62 @@ class DataManager {
...
@@ -125,6 +127,62 @@ class DataManager {
return
null
;
return
null
;
}
}
}
}
async
getRandomDuelBan
(
ip
)
{
const
repo
=
this
.
db
.
getRepository
(
RandomDuelBan_1
.
RandomDuelBan
);
try
{
const
ban
=
await
repo
.
findOne
(
ip
);
//console.log(ip, ban);
return
ban
;
}
catch
(
e
)
{
this
.
log
.
warn
(
`Failed to fetch random duel ban
${
ip
}
:
${
e
.
toString
()}
`
);
return
null
;
}
}
async
updateRandomDuelBan
(
ban
)
{
const
repo
=
this
.
db
.
getRepository
(
RandomDuelBan_1
.
RandomDuelBan
);
try
{
await
repo
.
save
(
ban
);
}
catch
(
e
)
{
this
.
log
.
warn
(
`Failed to update random duel ban
${
ban
.
ip
}
:
${
e
.
toString
()}
`
);
}
}
async
randomDuelBanPlayer
(
ip
,
reason
,
countadd
)
{
const
count
=
countadd
||
1
;
const
repo
=
this
.
db
.
getRepository
(
RandomDuelBan_1
.
RandomDuelBan
);
try
{
let
ban
=
await
repo
.
findOne
(
ip
);
if
(
ban
)
{
ban
.
count
+=
count
;
const
banTime
=
ban
.
count
>
3
?
Math
.
pow
(
2
,
ban
.
count
-
3
)
*
2
:
0
;
const
banDate
=
moment_1
.
default
(
ban
.
time
);
if
(
moment_1
.
default
().
isAfter
(
banDate
))
{
ban
.
time
=
moment_1
.
default
().
add
(
banTime
,
'
m
'
).
toDate
();
}
else
{
ban
.
time
=
moment_1
.
default
(
banDate
).
add
(
banTime
,
'
m
'
).
toDate
();
}
if
(
!
underscore_1
.
default
.
contains
(
ban
.
reasons
,
reason
))
{
ban
.
reasons
.
push
(
reason
);
}
ban
.
needTip
=
1
;
}
else
{
ban
=
new
RandomDuelBan_1
.
RandomDuelBan
();
ban
.
ip
=
ip
;
ban
.
time
=
moment_1
.
default
().
toDate
();
ban
.
count
=
count
;
ban
.
reasons
=
[
reason
];
ban
.
needTip
=
1
;
}
return
await
repo
.
save
(
ban
);
}
catch
(
e
)
{
this
.
log
.
warn
(
`Failed to update random duel ban
${
ip
}
:
${
e
.
toString
()}
`
);
return
null
;
}
}
}
}
exports
.
DataManager
=
DataManager
;
exports
.
DataManager
=
DataManager
;
//# sourceMappingURL=DataManager.js.map
//# sourceMappingURL=DataManager.js.map
\ No newline at end of file
data-manager/DataManager.ts
View file @
693361fd
...
@@ -5,6 +5,8 @@ import { Connection, ConnectionOptions, createConnection, Transaction } from "ty
...
@@ -5,6 +5,8 @@ import { Connection, ConnectionOptions, createConnection, Transaction } from "ty
import
{
CloudReplay
}
from
"
./entities/CloudReplay
"
;
import
{
CloudReplay
}
from
"
./entities/CloudReplay
"
;
import
{
CloudReplayPlayer
}
from
"
./entities/CloudReplayPlayer
"
;
import
{
CloudReplayPlayer
}
from
"
./entities/CloudReplayPlayer
"
;
import
{
Ban
}
from
"
./entities/Ban
"
;
import
{
Ban
}
from
"
./entities/Ban
"
;
import
{
RandomDuelBan
}
from
"
./entities/RandomDuelBan
"
;
import
_
from
"
underscore
"
;
export
interface
CloudReplayPlayerInfo
{
export
interface
CloudReplayPlayerInfo
{
...
@@ -134,4 +136,59 @@ export class DataManager {
...
@@ -134,4 +136,59 @@ export class DataManager {
return
null
;
return
null
;
}
}
}
}
async
getRandomDuelBan
(
ip
:
string
)
{
const
repo
=
this
.
db
.
getRepository
(
RandomDuelBan
);
try
{
const
ban
=
await
repo
.
findOne
(
ip
);
//console.log(ip, ban);
return
ban
;
}
catch
(
e
)
{
this
.
log
.
warn
(
`Failed to fetch random duel ban
${
ip
}
:
${
e
.
toString
()}
`
);
return
null
;
}
}
async
updateRandomDuelBan
(
ban
:
RandomDuelBan
)
{
const
repo
=
this
.
db
.
getRepository
(
RandomDuelBan
);
try
{
await
repo
.
save
(
ban
);
}
catch
(
e
)
{
this
.
log
.
warn
(
`Failed to update random duel ban
${
ban
.
ip
}
:
${
e
.
toString
()}
`
);
}
}
async
randomDuelBanPlayer
(
ip
:
string
,
reason
:
string
,
countadd
?:
number
){
const
count
=
countadd
||
1
;
const
repo
=
this
.
db
.
getRepository
(
RandomDuelBan
);
try
{
let
ban
=
await
repo
.
findOne
(
ip
);
if
(
ban
)
{
ban
.
count
+=
count
;
const
banTime
=
ban
.
count
>
3
?
Math
.
pow
(
2
,
ban
.
count
-
3
)
*
2
:
0
;
const
banDate
=
moment
(
ban
.
time
);
if
(
moment
().
isAfter
(
banDate
))
{
ban
.
time
=
moment
().
add
(
banTime
,
'
m
'
).
toDate
();
}
else
{
ban
.
time
=
moment
(
banDate
).
add
(
banTime
,
'
m
'
).
toDate
();
}
if
(
!
_
.
contains
(
ban
.
reasons
,
reason
))
{
ban
.
reasons
.
push
(
reason
);
}
ban
.
needTip
=
1
;
}
else
{
ban
=
new
RandomDuelBan
();
ban
.
ip
=
ip
;
ban
.
time
=
moment
().
toDate
();
ban
.
count
=
count
;
ban
.
reasons
=
[
reason
];
ban
.
needTip
=
1
;
}
return
await
repo
.
save
(
ban
);
}
catch
(
e
)
{
this
.
log
.
warn
(
`Failed to update random duel ban
${
ip
}
:
${
e
.
toString
()}
`
);
return
null
;
}
}
}
}
data-manager/entities/RandomDuelBan.js
0 → 100644
View file @
693361fd
"
use strict
"
;
var
__decorate
=
(
this
&&
this
.
__decorate
)
||
function
(
decorators
,
target
,
key
,
desc
)
{
var
c
=
arguments
.
length
,
r
=
c
<
3
?
target
:
desc
===
null
?
desc
=
Object
.
getOwnPropertyDescriptor
(
target
,
key
)
:
desc
,
d
;
if
(
typeof
Reflect
===
"
object
"
&&
typeof
Reflect
.
decorate
===
"
function
"
)
r
=
Reflect
.
decorate
(
decorators
,
target
,
key
,
desc
);
else
for
(
var
i
=
decorators
.
length
-
1
;
i
>=
0
;
i
--
)
if
(
d
=
decorators
[
i
])
r
=
(
c
<
3
?
d
(
r
)
:
c
>
3
?
d
(
target
,
key
,
r
)
:
d
(
target
,
key
))
||
r
;
return
c
>
3
&&
r
&&
Object
.
defineProperty
(
target
,
key
,
r
),
r
;
};
var
__metadata
=
(
this
&&
this
.
__metadata
)
||
function
(
k
,
v
)
{
if
(
typeof
Reflect
===
"
object
"
&&
typeof
Reflect
.
metadata
===
"
function
"
)
return
Reflect
.
metadata
(
k
,
v
);
};
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
value
:
true
});
exports
.
RandomDuelBan
=
void
0
;
const
typeorm_1
=
require
(
"
typeorm
"
);
let
RandomDuelBan
=
/** @class */
(()
=>
{
let
RandomDuelBan
=
class
RandomDuelBan
{
setNeedTip
(
need
)
{
this
.
needTip
=
need
?
1
:
0
;
}
getNeedTip
()
{
return
this
.
needTip
>
0
?
true
:
false
;
}
};
__decorate
([
typeorm_1
.
PrimaryColumn
({
type
:
"
varchar
"
,
length
:
64
}),
__metadata
(
"
design:type
"
,
String
)
],
RandomDuelBan
.
prototype
,
"
ip
"
,
void
0
);
__decorate
([
typeorm_1
.
Column
(
"
datetime
"
),
__metadata
(
"
design:type
"
,
Date
)
],
RandomDuelBan
.
prototype
,
"
time
"
,
void
0
);
__decorate
([
typeorm_1
.
Column
(
"
smallint
"
),
__metadata
(
"
design:type
"
,
Number
)
],
RandomDuelBan
.
prototype
,
"
count
"
,
void
0
);
__decorate
([
typeorm_1
.
Column
({
type
:
"
simple-array
"
}),
__metadata
(
"
design:type
"
,
Array
)
],
RandomDuelBan
.
prototype
,
"
reasons
"
,
void
0
);
__decorate
([
typeorm_1
.
Column
({
type
:
"
tinyint
"
,
unsigned
:
true
}),
__metadata
(
"
design:type
"
,
Number
)
],
RandomDuelBan
.
prototype
,
"
needTip
"
,
void
0
);
RandomDuelBan
=
__decorate
([
typeorm_1
.
Entity
()
],
RandomDuelBan
);
return
RandomDuelBan
;
})();
exports
.
RandomDuelBan
=
RandomDuelBan
;
//# sourceMappingURL=RandomDuelBan.js.map
\ No newline at end of file
data-manager/entities/RandomDuelBan.ts
0 → 100644
View file @
693361fd
import
{
Column
,
Entity
,
PrimaryColumn
}
from
"
typeorm
"
;
@
Entity
()
export
class
RandomDuelBan
{
@
PrimaryColumn
({
type
:
"
varchar
"
,
length
:
64
})
ip
:
string
;
@
Column
(
"
datetime
"
)
time
:
Date
;
@
Column
(
"
smallint
"
)
count
:
number
;
@
Column
({
type
:
"
simple-array
"
})
reasons
:
string
[]
@
Column
({
type
:
"
tinyint
"
,
unsigned
:
true
})
needTip
:
number
;
setNeedTip
(
need
:
boolean
)
{
this
.
needTip
=
need
?
1
:
0
;
}
getNeedTip
()
{
return
this
.
needTip
>
0
?
true
:
false
;
}
}
\ No newline at end of file
ygopro-server.coffee
View file @
693361fd
This diff is collapsed.
Click to expand it.
ygopro-server.js
View file @
693361fd
This diff is collapsed.
Click to expand it.
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