public async Task Process(OpenBattle openBattle) { if (!IsLoggedIn) { return; } if (MyBattle != null) { await Respond("You are already in a battle"); return; } openBattle.Header.Title = openBattle.Header.Title.Truncate(200); var battle = new ServerBattle(server, Name); battle.UpdateWith(openBattle.Header); server.Battles[battle.BattleID] = battle; await server.Broadcast(server.ConnectedUsers.Keys, new BattleAdded() { Header = battle.GetHeader() }); await Process(new JoinBattle() { BattleID = battle.BattleID, Password = openBattle.Header.Password, }); }
public async Task Process(OpenBattle openBattle) { if (!IsLoggedIn) { return; } if (string.IsNullOrEmpty(openBattle.Header.Password) && User.BanVotes) { await Respond("Your rights have been restricted. You can only open passworded battles. Check your user page for details."); return; } if (MyBattle != null) { await Respond("You are already in a battle"); return; } if (openBattle.Header.Mode != null && !Enum.IsDefined(typeof(AutohostMode), openBattle.Header.Mode)) { await Respond("Incorrect battle type"); return; } openBattle.Header.Title = openBattle.Header.Title.Truncate(200); var battle = new ServerBattle(server, Name); battle.UpdateWith(openBattle.Header); server.Battles[battle.BattleID] = battle; await server.Broadcast(server.ConnectedUsers.Keys, new BattleAdded() { Header = battle.GetHeader() }); await Process(new JoinBattle() { BattleID = battle.BattleID, Password = openBattle.Header.Password, }); }
public async Task Process(OpenBattle openBattle) { if (!IsLoggedIn) { return; } if (state.Battles.Values.Any(y => y.Founder == User)) { // already opened a battle await Respond("You already opened a battle"); return; } if (MyBattle != null) { await Respond("You are already in a battle"); return; } var battleID = Interlocked.Increment(ref state.BattleCounter); var h = openBattle.Header; h.BattleID = battleID; h.Founder = Name; var battle = new Battle(); battle.UpdateWith(h, (n) => state.ConnectedUsers[n].User); battle.Users[Name] = new UserBattleStatus(Name, User); state.Battles[battleID] = battle; MyBattle = battle; h.Password = h.Password != null ? "?" : null; // dont send pw to client var clis = state.ConnectedUsers.Values.ToList(); await state.Broadcast(clis, new BattleAdded() { Header = h }); await state.Broadcast(clis, new JoinedBattle() { BattleID = battleID, User = Name }); }