private void addPlayerToPeerToTournaments(IPeer peer, PreTournamentGame newTournament) { if (peerToTournaments.ContainsKey(peer.Id) == false) { peerToTournaments.Add(peer.Id, newTournament); return; } PreTournamentGame oldTournament = peerToTournaments[peer.Id]; if (SpectatorAuthModule.existsAdmin(peer)) //Admin { closeTournament(oldTournament); peerToTournaments.Remove(peer.Id); } else //User { if (oldTournament.getRoomID() != newTournament.getRoomID()) { removePlayerFromGame(peer, oldTournament); } else { return; } } peerToTournaments.Add(peer.Id, newTournament); }
private bool isValidAdmin(IIncommingMessage rawMsg) { if (SpectatorAuthModule.existsAdmin(rawMsg.Peer) == false) { rawMsg.Respond("Peer ID is not a registred Admin", ResponseStatus.Error); return(false); } return(true); }
private void handleRequestSpectatorGames(IIncommingMessage msg) { if (SpectatorAuthModule.existsAdmin(msg.Peer) == false) { return; } byte[] bytes = allGamesList.Select(g => g.convertToGameInfoPacket()).Select(l => (ISerializablePacket)l).ToBytes(); msg.Respond(bytes, ResponseStatus.Success); }
public void handleReconnectPlayer(IIncommingMessage rawMsg) { TournamentReconnectPlayer info = rawMsg.Deserialize <TournamentReconnectPlayer>(); RunningTournamentGame game; if (findGame(info.tournamentID, out game, rawMsg) && SpectatorAuthModule.existsAdmin(rawMsg.Peer)) { game.reconnectPlayer(info.username); } }
public void handleForeceRoundWinner(IIncommingMessage rawMsg) { TournamentForceWinnerMessage info = rawMsg.Deserialize <TournamentForceWinnerMessage>(); RunningTournamentGame game; if (findGame(info.tournamentID, out game, rawMsg) && SpectatorAuthModule.existsAdmin(rawMsg.Peer)) { game.forceIndexWinner(info.roundID, info.winIndex); } }
private void handleRoundStarted(IIncommingMessage rawMsg) { TournamentPreGameInfo info = rawMsg.Deserialize <TournamentPreGameInfo>(); RunningTournamentGame game; if (findGame(info.tournamentID, out game, rawMsg) && SpectatorAuthModule.existsAdmin(rawMsg.Peer)) { game.startRound(info.roundID); } }
public void handleCreateTournament(IIncommingMessage rawMsg) { IPeer peer = rawMsg.Peer; if (SpectatorAuthModule.existsAdmin(peer) == false) { rawMsg.Respond("You don't have admin permission", ResponseStatus.Failed); return; } TournamentInfoMsg msg = rawMsg.Deserialize <TournamentInfoMsg>(); string key = generateGameKey(); PreTournamentGame newTournament = new PreTournamentGame(msg, peer, key); currentPreTournaments.Add(key, newTournament); addPlayerToPeerToTournaments(rawMsg.Peer, newTournament); rawMsg.Respond(key, ResponseStatus.Success); newTournament.updateAdmin(); Debug.LogError("Created Tournament: " + key + " With admin: " + rawMsg.Peer.Id); }