Exemple #1
0
    // Send stats for all players in all parties
    protected void SendAllPlayerStats()
    {
        Entity topScorerAllTeams = GameServerParty.GetTopScorerAllTeams();

        foreach (var pty in GameServerParty.partyList)
        {
            var topScorerOwnTeam = pty.topScorer;

            foreach (Player player in pty.members)
            {
                PlayerQueueStats queueStats = player.stats.total;

                queueStats.secondsPlayed = secondsPlayed;
                queueStats.wins          = (player.party == winnerParty ? 1 : 0);
                queueStats.losses        = (player.party != winnerParty ? 1 : 0);

                // Calculate top scorer when not in 1v1
                if (QueueSettings.queueIndex != 0)
                {
                    queueStats.topScorerOwnTeam  = (player == topScorerOwnTeam ? 1 : 0);
                    queueStats.topScorerAllTeams = (player == topScorerAllTeams ? 1 : 0);
                }

                if (player.accountId != "")
                {
                    // Stats
                    StartCoroutine(ServerGameDB.SendAccountStats(player));

                    // Artifact rewards
                    StartCoroutine(ServerGameDB.SendArtifactRewards(player));
                }
            }
        }
    }
Exemple #2
0
    // Draws the score for one party
    void DrawPartyScore(GameServerParty pty, int width, int height)
    {
        GUI.color = pty.color;

        // Party total score
        GUI.backgroundColor = new Color(1.0f, 1.0f, 1.0f, 0.9f);
        GUI.Box(new Rect(0, 0, width, height), pty.name, partyBoxStyle);

        int memberCount    = 5;
        int marginTitleBar = height / (memberCount + 2);
        int plHeight       = (height - marginTitleBar * 2) / memberCount;
        int counter        = 0;

        // Header
        GUI.color = new Color(1.0f, 1.0f, 1.0f, 0.8f);

        /*GUILayout.BeginHorizontal();
         * GUILayout.Label(" ", nameStyle);
         * GUILayout.Label("Score", scoreStyle);
         * GUILayout.Label("Damage", scoreStyle);
         * GUILayout.Label("CC", scoreStyle);
         * GUILayout.Label("Kills", scoreStyle);
         * GUILayout.Label("Deaths", scoreStyle);
         * GUILayout.Label("Ping", scoreStyle);
         * GUILayout.Label("Ranking", scoreStyle);
         * GUILayout.EndHorizontal();*/

        GUI.Label(new Rect(width - marginX - 6 * columnWidth, marginTitleBar, columnWidth, plHeight), "Score", scoreStyle);
        GUI.Label(new Rect(width - marginX - 5 * columnWidth, marginTitleBar, columnWidth, plHeight), "Damage", scoreStyle);
        GUI.Label(new Rect(width - marginX - 4 * columnWidth, marginTitleBar, columnWidth, plHeight), "CC", scoreStyle);
        GUI.Label(new Rect(width - marginX - 3 * columnWidth, marginTitleBar, columnWidth, plHeight), "K / D / A", scoreStyle);
        GUI.Label(new Rect(width - marginX - 2 * columnWidth, marginTitleBar, columnWidth, plHeight), "Ping", scoreStyle);
        GUI.Label(new Rect(width - marginX - columnWidth, marginTitleBar, columnWidth, plHeight), "Ranking", scoreStyle);

        GUI.color = new Color(1.0f, 1.0f, 1.0f, 1.0f);

        // Sort by score
        // TODO: Only sort when needed
        var sortedMemberList =
            from p in pty.members
            orderby p.score descending
            select p;

        foreach (Player player in sortedMemberList)
        {
            using (new GUIArea(new Rect(0, marginTitleBar * 2 + counter * plHeight, width, plHeight))) {
                DrawPlayerScore(player, width, plHeight);
            }

            counter += 1;
        }
    }
Exemple #3
0
    // TODO: Make use of partyCount
    public static void CreateParties(int partyCount, int expectedMemberCount = 0)
    {
        for (int i = 0; i < partyCount; i++)
        {
            Color color = Color.black;

            // Not on server side
            if (ServerInit.instance == null)
            {
                color = PartyColors.instance.colors[i];
            }

            var pty = new GameServerParty("Team " + (i + 1), color);
            pty.expectedMemberCount = expectedMemberCount;
        }
    }
Exemple #4
0
    public void ReceiveServerType(ServerType type)
    {
        LogManager.General.Log("Received server type: " + type);
        GameManager.serverType = type;
        GameManager.gameEnded  = false;
        MapManager.InitPhysics(type);

        if (type == ServerType.FFA)
        {
            GameServerParty.CreateParties(10, 1);
        }
        else if (type == ServerType.Arena)
        {
            GameServerParty.CreateParties(2);
        }
        else
        {
            GameServerParty.CreateParties(1);
        }
    }
Exemple #5
0
    public void ClientReady(uLink.NetworkMessageInfo info)
    {
        if (info.sender != networkView.owner)
        {
            return;
        }

        // Let the others know
        this.networkView.RPC("Ready", uLink.RPCMode.OthersExceptOwner);
        this.Ready();

        if (!GameManager.gameStarted)
        {
            // Start conditions
            if (GameServerParty.AllPartiesReady())
            {
                // Start game after a few seconds
                gameMode.SendGameStartCountdown();
            }
        }
    }
Exemple #6
0
    // Loads a new map
    public static IEnumerator LoadMapAsync(string mapName, CallBack func = null)
    {
        DeleteOldMap();

        LogManager.General.Log("[" + mapName + "] Checking scene");

        if (Application.CanStreamedLevelBeLoaded(mapName))
        {
            LogManager.General.Log("[" + mapName + "] Map can be loaded");
        }
        else
        {
            // Wait for version info download to finish
            while (!AssetBundlesManager.instance.isReady)
            {
                yield return(new WaitForSeconds(0.02f));
            }

            // Download level
            var mapURL     = AssetBundlesManager.instance.GetMapURL(mapName);
            var mapVersion = AssetBundlesManager.instance.GetMapVersion(mapName);
            LogManager.General.Log("Downloading map '" + mapName + "' version " + mapVersion + " from " + mapURL);
            var download = WWW.LoadFromCacheOrDownload(mapURL, mapVersion);

            if (LoadingScreen.instance != null)
            {
                LoadingScreen.instance.downloadingText = "Downloading map: <color=yellow>" + mapName + "</color>...";
                LoadingScreen.instance.asyncDownload   = download;
            }

            yield return(download);

            if (download.error == null)
            {
                var bundle = download.assetBundle;
                LogManager.General.Log("Successfully downloaded " + mapName + bundle);
            }
            else
            {
                LogManager.General.LogError("Failed downloading map: " + mapName + " (" + download.error + ")");
            }

            if (!Application.CanStreamedLevelBeLoaded(mapName))
            {
                LogManager.General.LogError("Map can not be loaded: " + mapName);
            }
        }

        // Load map
        LogManager.General.Log("Loading map '" + mapName + "'...");
        currentMapName = mapName;

        var asyncLoadLevel = Application.LoadLevelAdditiveAsync(mapName);

        if (LoadingScreen.instance != null)
        {
            LoadingScreen.instance.loadingText    = "Loading map: <color=yellow>" + mapName + "</color>...";
            LoadingScreen.instance.asyncLoadLevel = asyncLoadLevel;
        }

        yield return(asyncLoadLevel);

        LogManager.General.Log("Finished loading map: " + mapName);

        // Try getting mapInstance 5 times (maximum)
        for (int i = 1; i <= 5; i++)
        {
            mapInstance = GameObject.FindGameObjectWithTag("Map");

            if (mapInstance == null)
            {
                LogManager.General.LogWarning("Couldn't find the map, mapInstance is null: Retrying.");
                yield return(new WaitForSeconds(0.01f));
            }
            else
            {
                break;
            }
        }

        if (mapInstance == null)
        {
            LogManager.General.LogError("Couldn't find the map, mapInstance is null");
        }

        mapIntro = mapInstance.GetComponent <Intro>();
        LogManager.General.Log("Map intro: " + mapIntro);

        mapBounds = mapInstance.GetComponent <MapBoundary>().bounds;
        LogManager.General.Log("Map bounds: " + mapBounds);

        // Occlusion area
        occlusionArea = mapInstance.transform.FindChild("Occlusion Area");
        if (occlusionArea != null)
        {
            LogManager.General.Log("Occlusion culling information available");
            occlusionCullingActive = true;
        }
        else
        {
            LogManager.General.Log("Occlusion culling information not available");
            occlusionCullingActive = false;
        }

        // Play music
        if (MusicManager.instance != null)
        {
            MusicManager.instance.PlayCategory(mapInstance.GetComponent <MusicCategory>());
        }

        // Update spawn locations
        GameServerParty.UpdateSpawns();

        // Delete NPCs on PvP areas
        if (GameManager.isPvP)
        {
            DeleteNPCs();
        }

        // Update sun shafts caster

        /*if(isServer) {
         *      var sun = GameObject.FindGameObjectWithTag("Sun");
         *      var sunShafts = Camera.main.GetComponent<SunShafts>();
         *      if(sun != null && sunShafts != null) {
         *              // TODO: Why doesn't this work?
         *              sunShafts.sunTransform = sun.transform;
         *              LogManager.General.Log("Updated sun shafts caster to " + sun.ToString() + ", " + sun.transform.ToString());
         *      } else {
         *              LogManager.General.LogWarning("Couldn't find sun (did you use the 'Sun' tag?)");
         *      }
         * }*/

        // Try to free up some RAM
        PerformanceMonitor.FreeRAM();

        // Custom callback function
        if (func != null)
        {
            func();
        }
    }
Exemple #7
0
    // Awake
    void Awake()
    {
        // TODO: Checks...
        instance = this;

        // This will be reset later if -batchmode was specified
#if UNITY_STANDALONE_WIN
        isTestServer = true;
#else
        isTestServer = false;
#endif

        // Default values
        serverPort = defaultServerPort;
        partyCount = 1;

        // -party0 account1 -party1 account2
        // -batchmode -port7100
        // taskkill /IM
        LogManager.General.Log("Parsing command line arguments");
        string[] args    = System.Environment.GetCommandLineArgs();
        int      partyId = GameServerParty.Undefined;

        foreach (string arg in args)
        {
            LogManager.General.Log("Command line argument: '" + arg + "'");

            // Overwrite port
            if (arg.StartsWith("-port") && arg.Length > "-port".Length)
            {
                serverPort = int.Parse(arg.Substring(5));
                // Batchmode
            }
            else if (arg == "-batchmode")
            {
                batchMode    = true;
                isTestServer = false;
                // Party count
            }
            else if (arg.StartsWith("-partycount") && arg.Length > "-partycount".Length)
            {
                partyCount = int.Parse(arg.Substring("-partycount".Length));

                LogManager.General.Log(string.Format("Creating parties: {0}", partyCount));
                GameServerParty.partyList.Clear();
                GameServerParty.CreateParties(partyCount);
                // Teams
            }
            else if (arg.StartsWith("-party") && arg.Length > "-party".Length)
            {
                partyId            = int.Parse(arg.Substring("-party".Length));
                restrictedAccounts = true;
                // Map
            }
            else if (arg.StartsWith("-map") && arg.Length > "-map".Length)
            {
                mapName = arg.Substring("-map".Length);
                // Lobby IP
            }
            else if (arg.StartsWith("-lobbyIP") && arg.Length > "-lobbyIP".Length)
            {
                lobbyIP = arg.Substring("-lobbyIP".Length);
                // Lobby Port
            }
            else if (arg.StartsWith("-lobbyPort") && arg.Length > "-lobbyPort".Length)
            {
                lobbyPort = int.Parse(arg.Substring("-lobbyPort".Length));
                // Server type
            }
            else if (arg.StartsWith("-type") && arg.Length > "-type".Length)
            {
                string serverTypeString = arg.Substring("-type".Length);
                switch (serverTypeString)
                {
                case "Arena":
                    GameManager.serverType = ServerType.Arena;
                    break;

                case "Town":
                    GameManager.serverType = ServerType.Town;
                    break;

                case "FFA":
                    GameManager.serverType = ServerType.FFA;
                    break;

                case "World":
                    GameManager.serverType = ServerType.World;
                    break;
                }
                // Database IP
            }
            else if (arg.StartsWith("-databaseIP") && arg.Length > "-databaseIP".Length)
            {
                databaseIP = arg.Substring("-databaseIP".Length);
                // Database Port
            }
            else if (arg.StartsWith("-databasePort") && arg.Length > "-databasePort".Length)
            {
                databasePort = int.Parse(arg.Substring("-databasePort".Length));
                // Account ID
            }
            else
            {
                if (partyId >= 0 && partyId < GameServerParty.partyList.Count)
                {
                    var currentParty = GameServerParty.partyList[partyId];
                    accountToParty[arg] = currentParty;
                    currentParty.expectedMemberCount += 1;
                }
            }
        }

        // For testing
        if (isTestServer)
        {
            GameManager.serverType = testServerType;
        }
        else
        {
            if (!string.IsNullOrEmpty(databaseIP))
            {
                Database.AddNode("riak", databaseIP, databasePort, 10, Defaults.WriteTimeout, Defaults.ReadTimeout);
                Database.Connect();
            }
            else
            {
                LogManager.DB.LogError("No database address specified, can't connect to the database");
            }
        }

        // Create at least 1 party if no party count has been specified
        if (GameServerParty.partyList.Count != partyCount)
        {
            switch (GameManager.serverType)
            {
            case ServerType.Arena:
                partyCount = 2;
                break;

            case ServerType.FFA:
                partyCount = 10;
                break;
            }

            LogManager.General.Log(string.Format("Creating parties: {0}", partyCount));
            GameServerParty.partyList.Clear();
            GameServerParty.CreateParties(partyCount);
        }

        // Server type
        LogManager.General.Log("Server type: " + GameManager.serverType);
        MapManager.InitPhysics(GameManager.serverType);

        if (restrictedAccounts)
        {
            LogManager.General.Log("Server is restricted to the following accounts: " + accountToParty.Keys);
        }

        if (GameManager.isArena)
        {
            QueueSettings.queueIndex = accountToParty.Count / 2 - 1;
            LogManager.General.Log("Queue type is: " + (QueueSettings.queueIndex + 1) + "v" + (QueueSettings.queueIndex + 1));
        }
        else if (GameManager.isFFA)
        {
            QueueSettings.queueIndex = 0;
            LogManager.General.Log("Queue type is: " + (QueueSettings.queueIndex + 1) + "v" + (QueueSettings.queueIndex + 1));
        }

        // Server batchmode
        //if(batchMode) {
        LogManager.General.Log("Batchmode is being used: Destroy the camera and disable renderers");

        // Destroy the camera
        Destroy(Camera.main);

        // Disable renderers in batchmode
        DisableRenderers(creatorPrefab);

        // No statistics GUI
#if UNITY_EDITOR
        GetComponent <uLinkStatisticsGUI>().enabled = true;
#endif

        // No audio
        AudioListener.pause = true;

        // Disable all game modes just to be safe
        var gameModes = GetComponents <GameMode>();
        foreach (var mode in gameModes)
        {
            mode.enabled = false;
        }

        // Pick correct game mode
        int maxPlayerCount = 0;
        switch (GameManager.serverType)
        {
        case ServerType.Arena:
            gameMode = GetComponent <ArenaGameMode>();
            int maxSpectators = 10;
            maxPlayerCount = 10 + maxSpectators;
            break;

        case ServerType.Town:
            gameMode       = GetComponent <TownGameMode>();
            maxPlayerCount = 1024;
            break;

        case ServerType.FFA:
            gameMode       = GetComponent <FFAGameMode>();
            maxPlayerCount = 10;
            break;

        case ServerType.World:
            gameMode       = GetComponent <WorldGameMode>();
            maxPlayerCount = 1024;
            break;
        }

        // FFA
        if (GameManager.isFFA)
        {
            GameServerParty.partyList.Clear();
            GameServerParty.CreateParties(10, 1);
        }

        // Public key
        NetworkHelper.InitPublicLobbyKey();

        // Started by uZone?
        if (uZone.Instance.wasStartedByuZone)
        {
            // Listen to lobby events and RPCs
            Lobby.AddListener(this);

            IPAndPortCallBack connectToServices = (host, port) => {
                // Connect to lobby
                LogManager.General.Log(string.Format("Connecting to lobby as server {0}:{1}", host, port));
                Lobby.ConnectAsServer(host, port);

                // Update members in case we downloaded the info
                lobbyIP   = host;
                lobbyPort = port;

                // Set up callback
                uZone.Instance.GlobalEvents events = new uZone.Instance.GlobalEvents();
                events.onInitialized = uZone_OnInitialized;

                // This will tell uZone that the instance is ready
                // and we can let other players connect to it
                LogManager.General.Log("Initializing the uZone instance");
                uZone.Instance.Initialize(events);
            };

            // uLobby and uZone
#if UNITY_STANDALONE_WIN
            lobbyIP   = "127.0.0.1";
            lobbyPort = 1310;

            connectToServices(lobbyIP, lobbyPort);
#else
            if (string.IsNullOrEmpty(lobbyIP))
            {
                StartCoroutine(NetworkHelper.DownloadIPAndPort("https://battleofmages.com/scripts/login-server-ip.php", connectToServices));
            }
            else
            {
                connectToServices(lobbyIP, lobbyPort);
            }
#endif
        }

        // Load map
        StartCoroutine(MapManager.LoadMapAsync(
                           mapName,

                           // Map is loaded asynchronously...
                           // When it's finished, we use the callback:
                           () => {
            // Register codecs for serialization
            GameDB.InitCodecs();

            // Server port
            if (!isTestServer)
            {
                try {
                    serverPort = uZone.Instance.port;
                    LogManager.General.Log("Using port assigned from uZone: " + serverPort);
                } catch {
                    LogManager.General.Log("Failed to retrieve port info from uZone! Using port " + serverPort);
                }
            }
            else
            {
                LogManager.General.Log("Using test server port: " + serverPort);
            }

            // Init server
            LogManager.General.Log("Initializing the server on port " + serverPort);
            uLink.Network.InitializeServer(maxPlayerCount, serverPort);

            // Encryption
            LogManager.General.Log("Initializing security");
            uLink.Network.InitializeSecurity(true);

#if !UNITY_EDITOR
            // Clean up
            DestroyServerAssets();
#endif
            // Send ready message if we didn't do it yet
            SendReadyMessage();
        }
                           ));
    }