Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bancho.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
4
Issues
4
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
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
Hugo "ThePooN" Denizart
bancho.js
Commits
ad333d70
Commit
ad333d70
authored
Nov 01, 2019
by
Hugo "ThePooN" Denizart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BanchoLobby: Fix updateSettings race condition
Closes
#35
. See this issue for further details.
parent
e4e40347
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
58 deletions
+59
-58
lib/Multiplayer/BanchoLobby.js
lib/Multiplayer/BanchoLobby.js
+59
-58
No files found.
lib/Multiplayer/BanchoLobby.js
View file @
ad333d70
...
...
@@ -780,80 +780,81 @@ class BanchoLobby extends EventEmitter {
return
this
.
updateSettingsPromise
;
return
this
.
updateSettingsPromise
=
new
Promise
((
callerResolve
,
callerReject
)
=>
{
this
.
pushSlotsUpdateQueue
(()
=>
{
this
.
channel
.
sendMessage
(
"
!mp settings
"
+
this
.
randomString
());
// Beginning of the !mp settings message will be handled by handleBanchoBotMessage; ending (player infos) will be handled in the following listener.
let
amountOfPlayers
=
null
;
const
slots
=
this
.
_createSlotsArray
();
const
listener
=
(
msg
)
=>
{
if
(
msg
.
user
.
ircUsername
.
toLowerCase
()
==
"
banchobot
"
)
{
if
(
amountOfPlayers
==
null
)
{
const
playersRegex
=
Regexes
.
regexes
.
playersAmount
(
msg
.
message
);
if
(
playersRegex
)
{
amountOfPlayers
=
playersRegex
.
playersAmount
;
if
(
amountOfPlayers
==
0
)
{
this
.
channel
.
sendMessage
(
"
!mp settings
"
+
this
.
randomString
());
// Beginning of the !mp settings message will be handled by handleBanchoBotMessage; ending (player infos) will be handled in the following listener.
let
amountOfPlayers
=
null
;
const
slots
=
this
.
_createSlotsArray
()
;
const
listener
=
(
msg
)
=>
{
if
(
msg
.
user
.
ircUsername
.
toLowerCase
()
==
"
banchobot
"
)
{
if
(
amountOfPlayers
==
null
)
{
const
playersRegex
=
Regexes
.
regexes
.
playersAmount
(
msg
.
message
);
if
(
playersRegex
)
{
amountOfPlayers
=
playersRegex
.
playersAmount
;
if
(
amountOfPlayers
==
0
)
{
this
.
pushSlotsUpdateQueue
(()
=>
{
this
.
slots
=
this
.
_createSlotsArray
();
this
.
slotsUpdateCallback
();
callerResolve
();
this
.
updateSettingsPromise
=
null
;
this
.
channel
.
removeListener
(
"
message
"
,
listener
);
}
}
);
this
.
channel
.
removeListener
(
"
message
"
,
listener
);
}
}
else
{
const
playerRegex
=
/^Slot
(\d
+
)
+
(
Not Ready|Ready|No Map
)
+https:
\/\/
osu
\.
ppy
\.
sh
\/
u
\/(\d
+
)
(
.+
)
$/
;
if
(
playerRegex
.
test
(
msg
.
message
))
{
const
match
=
playerRegex
.
exec
(
msg
.
message
);
this
.
getPlayerById
(
Number
(
match
[
3
])).
then
((
player
)
=>
{
slots
[
Number
(
match
[
1
])
-
1
]
=
player
;
player
.
state
=
BanchoLobbyPlayerStates
[
match
[
2
]]
;
player
.
isHost
=
false
;
player
.
team
=
null
;
player
.
mods
=
(
this
.
freemod
)
?
[]
:
this
.
mods
;
let
metadatasString
=
match
[
4
].
substring
(
player
.
user
.
username
.
length
).
trim
()
;
if
(
metadatasString
.
length
>
0
)
{
metadatasString
=
metadatasString
.
substr
(
1
,
metadatasString
.
length
-
2
);
for
(
let
metadatasSplit
of
metadatasString
.
split
(
"
/
"
))
{
metadatasSplit
=
metadatasSplit
.
trim
();
switch
(
metadatasSplit
)
{
case
"
Host
"
:
player
.
isHost
=
true
;
break
;
case
"
Team Blue
"
:
player
.
team
=
BanchoLobbyTeams
.
Blue
;
break
;
case
"
Team Red
"
:
player
.
team
=
BanchoLobbyTeams
.
Red
;
break
;
default
:
player
.
mods
=
BanchoMods
.
parseLongMods
(
metadatasSplit
);
}
}
else
{
const
playerRegex
=
/^Slot
(\d
+
)
+
(
Not Ready|Ready|No Map
)
+https:
\/\/
osu
\.
ppy
\.
sh
\/
u
\/(\d
+
)
(
.+
)
$/
;
if
(
playerRegex
.
test
(
msg
.
message
))
{
const
match
=
playerRegex
.
exec
(
msg
.
message
);
this
.
getPlayerById
(
Number
(
match
[
3
])).
then
((
player
)
=>
{
slots
[
Number
(
match
[
1
])
-
1
]
=
player
;
player
.
state
=
BanchoLobbyPlayerStates
[
match
[
2
]]
;
player
.
isHost
=
false
;
player
.
team
=
null
;
player
.
mods
=
(
this
.
freemod
)
?
[]
:
this
.
mods
;
let
metadatasString
=
match
[
4
].
substring
(
player
.
user
.
username
.
length
).
trim
();
if
(
metadatasString
.
length
>
0
)
{
metadatasString
=
metadatasString
.
substr
(
1
,
metadatasString
.
length
-
2
);
for
(
let
metadatasSplit
of
metadatasString
.
split
(
"
/
"
))
{
metadatasSplit
=
metadatasSplit
.
trim
();
switch
(
metadatasSplit
)
{
case
"
Host
"
:
player
.
isHost
=
true
;
break
;
case
"
Team Blue
"
:
player
.
team
=
BanchoLobbyTeams
.
Blue
;
break
;
case
"
Team Red
"
:
player
.
team
=
BanchoLobbyTeams
.
Red
;
break
;
default
:
player
.
mods
=
BanchoMods
.
parseLongMods
(
metadatasSplit
);
}
}
}
let
completedPlayers
=
0
;
for
(
const
slot
of
slots
)
{
if
(
slot
!=
null
)
completedPlayers
++
;
}
if
(
completedPlayers
==
amountOfPlayers
)
{
let
completedPlayers
=
0
;
for
(
const
slot
of
slots
)
{
if
(
slot
!=
null
)
completedPlayers
++
;
}
if
(
completedPlayers
==
amountOfPlayers
)
{
this
.
pushSlotsUpdateQueue
(()
=>
{
this
.
slots
=
slots
;
this
.
slotsUpdateCallback
();
callerResolve
();
this
.
updateSettingsPromise
=
null
;
this
.
channel
.
removeListener
(
"
message
"
,
listener
);
}
},
(
err
)
=>
{
this
.
slotsUpdateCallback
();
callerReject
(
err
);
});
}
});
this
.
channel
.
removeListener
(
"
message
"
,
listener
);
}
},
(
err
)
=>
{
callerReject
(
err
);
});
}
}
};
}
};
this
.
channel
.
on
(
"
message
"
,
listener
);
});
this
.
channel
.
on
(
"
message
"
,
listener
);
});
}
...
...
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