allow keeping owner

This commit is contained in:
Alberto Xamin 2024-10-29 16:37:04 +00:00
parent b2b9eac1cd
commit b45d04bf30
No known key found for this signature in database
GPG Key ID: 5ABFCD8A22EA6F5D
2 changed files with 9 additions and 5 deletions

View File

@ -122,6 +122,7 @@ class Game:
self.rpc_log = [] self.rpc_log = []
self.is_replay = False self.is_replay = False
self.replay_speed = 1 self.replay_speed = 1
self.owner: str | None = None
def shuffle_players(self): def shuffle_players(self):
if not self.started: if not self.started:
@ -254,6 +255,7 @@ class Game:
"available_expansions": self.available_expansions, "available_expansions": self.available_expansions,
"is_replay": self.is_replay, "is_replay": self.is_replay,
"characters_to_distribute": self.characters_to_distribute, "characters_to_distribute": self.characters_to_distribute,
"owner": self.owner,
}, },
) )
G.sio.emit("debug", room=self.name, data=self.debug) G.sio.emit("debug", room=self.name, data=self.debug)
@ -308,6 +310,8 @@ class Game:
if player.is_admin(): if player.is_admin():
self.feature_flags() self.feature_flags()
self.players.append(player) self.players.append(player)
if len(self.players) == 1:
self.owner = player.name
if len(self.players) > 7: if len(self.players) > 7:
if "dodge_city" not in self.expansions: if "dodge_city" not in self.expansions:
self.expansions.append("dodge_city") self.expansions.append("dodge_city")
@ -989,6 +993,8 @@ class Game:
self.deck = None self.deck = None
return True return True
else: else:
self.owner = next((p.name for p in self.players if not p.is_bot), None)
self.notify_room()
return False return False
def player_death(self, player: pl.Player, disconnected=False): def player_death(self, player: pl.Player, disconnected=False):

View File

@ -483,6 +483,7 @@ export default {
fullScreenEffects: [], fullScreenEffects: [],
showPopup: false, showPopup: false,
selectedExpansionInfo: {}, selectedExpansionInfo: {},
owner: undefined,
}), }),
sockets: { sockets: {
expansion_info(data) { expansion_info(data) {
@ -503,6 +504,7 @@ export default {
this.togglable_expansions = data.available_expansions; this.togglable_expansions = data.available_expansions;
this.expansions = data.expansions; this.expansions = data.expansions;
this.is_replay = data.is_replay; this.is_replay = data.is_replay;
this.owner = data.owner;
this.characters_to_distribute = data.characters_to_distribute; this.characters_to_distribute = data.characters_to_distribute;
this.players = data.players.map((x) => { this.players = data.players.map((x) => {
return { return {
@ -729,11 +731,7 @@ export default {
return ""; return "";
}, },
isRoomOwner() { isRoomOwner() {
if (this.players.length > 0) { return this.owner === this.username;
let pls = this.players.filter((x) => !x.is_bot);
return pls.length > 0 && pls[0].name == this.username;
}
return false;
}, },
startGameCard() { startGameCard() {
if (!this.started && this.players.length > 2 && this.isRoomOwner) { if (!this.started && this.players.length > 2 && this.isRoomOwner) {