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);
        }
    public override void Initialize(IServer server)
    {
        Debug.LogError("Init costum AuthModule");

        AlbotDBManager.initDB();
        AlbotDBManager.updateLoginInfo(new UserLoginInformation {
            username = "******", password = "******", isLoggedIn = false
        });
        AlbotDBManager.updateGameStat(new UserInfo {
            username = "******", profilePic = "6", roomActions = "0", logins = "0"
        });
        AlbotDBManager.updateLoginInfo(new UserLoginInformation {
            username = "******", password = "******", isLoggedIn = false
        });
        AlbotDBManager.updateGameStat(new UserInfo {
            username = "******", profilePic = "3", roomActions = "0", logins = "0"
        });
        AlbotDBManager.clearActiveUsers();
        AlbotDBManager.resetLoggedInUsers();

        server.SetHandler((short)CustomMasterServerMSG.login, handleLoginMsg);
        server.SetHandler((short)MsfOpCodes.GetPeerAccountInfo, HandleGetPeerAccountInfo);
        Component.FindObjectOfType <MasterServerBehaviour> ().PeerDisconnected += handleDissconnectedPeer;
        spectatorModule = Component.FindObjectOfType <SpectatorAuthModule> ();
    }
 public override void Initialize(IServer server)
 {
     singleton = this;
     server.SetHandler((short)CustomMasterServerMSG.adminLogin, handleLogin);
     server.SetHandler((short)CustomMasterServerMSG.adminLogout, handleLogout);
     Debug.LogError("Spectator Auth Init");
 }
 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);
        }