Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
7cee88f5
Commit
7cee88f5
authored
10 years ago
by
mcmlxxix
Browse files
Options
Downloads
Patches
Plain Diff
fixed inactivity timeout detection
fixed conversion of inactive players to AI some debug logging (to e.log)
parent
c6576e3f
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
xtrn/dicewarz2/service.js
+22
-12
22 additions, 12 deletions
xtrn/dicewarz2/service.js
with
22 additions
and
12 deletions
xtrn/dicewarz2/service.js
+
22
−
12
View file @
7cee88f5
var
root
=
argv
[
0
];
var
root
=
argv
[
0
];
if
(
!
file_exists
(
root
+
"
server.ini
"
))
{
throw
(
"
server initialization file missing
"
);
}
/* load server connection information from server.ini */
/* load server connection information from server.ini */
var
server_file
=
new
File
(
file_cfgname
(
root
,
"
server.ini
"
)
)
;
var
server_file
=
new
File
(
root
+
"
server.ini
"
);
server_file
.
open
(
'
r
'
,
true
);
server_file
.
open
(
'
r
'
,
true
);
var
serverAddr
=
server_file
.
iniGetValue
(
null
,
"
host
"
,
"
localhost
"
);
var
serverAddr
=
server_file
.
iniGetValue
(
null
,
"
host
"
);
var
serverPort
=
server_file
.
iniGetValue
(
null
,
"
port
"
,
10088
);
var
serverPort
=
server_file
.
iniGetValue
(
null
,
"
port
"
);
server_file
.
close
();
server_file
.
close
();
load
(
"
json-client.js
"
);
load
(
"
json-client.js
"
);
...
@@ -210,9 +212,11 @@ function scanInactivity() {
...
@@ -210,9 +212,11 @@ function scanInactivity() {
var
timeout
=
settings
.
inactivity_timeout
*
24
*
60
*
60
*
1000
;
var
timeout
=
settings
.
inactivity_timeout
*
24
*
60
*
60
*
1000
;
for
(
var
g
in
data
.
games
)
{
for
(
var
g
in
data
.
games
)
{
var
game
=
data
.
games
[
g
];
var
game
=
data
.
games
[
g
];
if
(
Date
.
now
()
-
timeout
>=
game
.
last_turn
)
{
elog
(
"
game
"
+
game
.
gameNumber
+
"
last turn:
"
+
game
.
last_turn
+
"
inactive:
"
+
(
Date
.
now
()
-
game
.
last_turn
));
if
(
Date
.
now
()
-
game
.
last_turn
>=
timeout
)
{
if
(
game
.
single_player
)
{
if
(
game
.
single_player
)
{
deleteGame
(
game
.
gameNumber
);
deleteGame
(
game
.
gameNumber
);
elog
(
"
inactive game deleted
"
);
}
}
else
if
(
game
.
status
==
status
.
PLAYING
)
{
else
if
(
game
.
status
==
status
.
PLAYING
)
{
var
player
=
game
.
players
[
game
.
turn
];
var
player
=
game
.
players
[
game
.
turn
];
...
@@ -224,13 +228,22 @@ function scanInactivity() {
...
@@ -224,13 +228,22 @@ function scanInactivity() {
turns
:
0
,
turns
:
0
,
moves
:
0
moves
:
0
}
}
client
.
write
(
game_id
,
"
games.
"
+
game
.
gameNumber
+
"
.players.
"
+
player
.
name
,
player
,
2
)
client
.
write
(
game_id
,
"
games.
"
+
game
.
gameNumber
+
"
.players.
"
+
game
.
turn
,
player
,
2
)
updateTurn
(
game
);
updateTurn
(
game
);
elog
(
"
inactive player changed to AI
"
);
}
}
}
}
}
}
}
}
/* error log / debug log */
function
elog
(
str
)
{
var
ef
=
new
File
(
root
+
"
e.log
"
);
ef
.
open
(
'
a
'
,
true
);
ef
.
writeln
(
str
+
"
(
"
+
system
.
timestr
()
+
"
)
"
);
ef
.
close
();
}
/* initialize service */
/* initialize service */
function
open
()
{
function
open
()
{
js
.
branch_limit
=
0
;
js
.
branch_limit
=
0
;
...
@@ -245,7 +258,8 @@ function open() {
...
@@ -245,7 +258,8 @@ function open() {
data
.
players
=
{};
data
.
players
=
{};
updateGames
();
updateGames
();
timer
.
addEvent
(
86400000
,
true
,
scanInactivity
);
scanInactivity
();
timer
.
addEvent
(
43200000
,
true
,
scanInactivity
);
log
(
LOG_INFO
,
"
Dicewarz II background service initialized
"
);
log
(
LOG_INFO
,
"
Dicewarz II background service initialized
"
);
}
}
...
@@ -267,14 +281,10 @@ function main() {
...
@@ -267,14 +281,10 @@ function main() {
try
{
try
{
open
();
open
();
main
();
main
();
close
();
close
();
}
catch
(
e
)
{
}
catch
(
e
)
{
var
ef
=
new
File
(
root
+
"
e.log
"
);
elog
(
e
.
toSource
());
ef
.
open
(
'
a
'
,
true
);
ef
.
writeln
(
e
.
toSource
());
ef
.
close
();
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment