예제 #1
0
    public void ConnectIP()
    {
        if (Topan.Network.isConnected)
        {
            return;
        }

        NetworkingGeneral.CreateInstance(cachedNetworking);
        Topan.Network.AddNetworkEventListener(this);
        TopanData initData = new TopanData();

        initData.Add("dat", NetworkingGeneral.ConvertToCombatant(AccountManager.profileData));
        PlayerPrefs.SetString("SavedIPConnect", DarkRef.RemoveSpaces(IPInput.value));
        PlayerPrefs.SetString("SavedPortConnect", portInput.value);
        Topan.Network.Connect(DarkRef.RemoveSpaces(IPInput.value), int.Parse(portInput.value), initData);
        GeneralVariables.lobbyManager.joiningLobby = true;
    }
예제 #2
0
    public void OnJoin(int number)
    {
        if (joining)
        {
            return;
        }

        if (onlineList)
        {
            if (Topan.MasterServer.hosts == null)
            {
                return;
            }
            else if (Topan.MasterServer.hosts.Count <= 0)
            {
                return;
            }

            if (Topan.MasterServer.hosts[number].playerCount >= Topan.MasterServer.hosts[number].maxPlayers)
            {
                return;
            }
        }
        else
        {
            if (Topan.Network.foundLocalGames == null)
            {
                return;
            }
            else if (Topan.Network.foundLocalGames.Count <= 0)
            {
                return;
            }

            /* Local version of max player limit restriction. Dunno?
             * if(Topan.MasterServer.hosts[number].playerCount == Topan.MasterServer.hosts[number].maxPlayers) {
             *  return;
             * }
             */
        }

        lobbyChat.chatOutput.ClearChatList();
        NetworkingGeneral.CreateInstance(cachedNetworking);
        joiningLobby = true;

        TopanData initData = new TopanData();

        initData.Add("dat", NetworkingGeneral.ConvertToCombatant(AccountManager.profileData));
        UICamera.selectedObject = null;

        if (onlineList)
        {
            joinHostInfo = serverList.displayHostedServers[number];
            Topan.Network.Connect(joinHostInfo, initData);
        }
        else
        {
            Topan.FoundGame toConnectLocal = Topan.Network.foundLocalGames[number];
            Topan.Network.Connect(toConnectLocal.serverEndpoint, initData);
        }
    }
예제 #3
0
    private IEnumerator StartServerCoroutine()
    {
        Topan.Network.AddNetworkEventListener(this);
        TopanData init = new TopanData();

        init.Add("dat", NetworkingGeneral.ConvertToCombatant(AccountManager.profileData));

        int port = 7100; //As default.

        if (portForwardCheckbox.value)
        {
            port = int.Parse(hostPortInput.value);
        }

        PlayerPrefs.SetInt("SavedMaxPlayers", (int)maxPlayerSlider.currentValue);
        PlayerPrefs.SetInt("PortForward", (portForwardCheckbox.value) ? 1 : 0);
        PlayerPrefs.SetInt("LocalServer", (hostLocalCheckbox.value) ? 1 : 0);
        PlayerPrefs.SetString("SavedPingLimit", pingLimitInput.value);
        PlayerPrefs.SetInt("SavedMapIndex", selectedMap);
        PlayerPrefs.SetInt("SavedGameMode", mSettingControl.gameModePopup.selectionIndex);

        Topan.Network.InitializeServer((int)(maxPlayerSlider.currentValue), port, !portForwardCheckbox.value, init);
        Topan.Network.GameName = gameNameInput.value;
        NetworkingGeneral.CreateInstance(cachedNetworking);

        if (!hostLocalCheckbox.value && !portForwardCheckbox.value)
        {
            int mapIndx = selectedMap;
            Topan.MasterServer.RegisterMasterServer(gameNameInput.value, true, AccountManager.profileData.username, mapIndx, gameTypeIndexes[mSettingControl.gameTypeName]);
        }

        GeneralVariables.server.InstantiateServer();

        yield return(null);

        yield return(null);

        UICamera.selectedObject = null;
        Topan.Network.SetServerInfo("s", UnityEngine.Random.seed);
        Topan.Network.SetServerInfo("dur", (byte)gameDurationSlider.currentDuration);
        Topan.Network.SetServerInfo("rc", (byte)roundCountSlider.currentRoundAmount);
        StartCoroutine(SelectMapRoutine(selectedMap));
        GeneralVariables.server.amountOfRounds = roundCountSlider.currentRoundAmount;
        GeneralVariables.lobbyManager.ResetButtons();
        moveCam.TargetPos(new Vector3(3840f, -800f, -700f));

        Topan.Network.SetServerInfo("sm", false);
        Topan.Network.SetServerInfo("rTK", (UInt16)0);
        Topan.Network.SetServerInfo("bTK", (UInt16)0);
        Topan.Network.SetServerInfo("rTD", (UInt16)0);
        Topan.Network.SetServerInfo("bTD", (UInt16)0);
        Topan.Network.SetServerInfo("rVic", (byte)0);
        Topan.Network.SetServerInfo("bVic", (byte)0);

        Topan.Network.SetServerInfo("gm", NetworkingGeneral.currentGameType.typeName);
        foreach (GM_SettingsControl.SettingInfo sInfo in mSettingControl.settingsList)
        {
            Topan.Network.SetServerInfo(sInfo.settingName, NetworkingGeneral.currentGameType.customSettings[sInfo.settingName].currentValue);
        }

        int setPingLimit = Mathf.Clamp(int.Parse(pingLimitInput.value), 100, 9999);

        GeneralVariables.server.pingLimit = setPingLimit;
        Topan.Network.SetServerInfo("plim", setPingLimit);
        Topan.Network.SetServerInfo("it", (byte)(idleTimeSlider.currentIdleTime / 5));

        yield return(null);

        Topan.Network.SetServerInfo("bC", (byte)bsMenu.amountSlider.currentValue);

        BotPlayer[]   newBots   = new BotPlayer[16]; //16 = maximum limit of players in a server
        List <string> prevNames = new List <string>();

        for (int i = 0; i < newBots.Length; i++)
        {
            CombatantInfo newInfo = new CombatantInfo();

            string randomName = DarkRef.RandomBotName();
            int    trials     = 0;
            while (prevNames.Contains(randomName) && trials < 10)
            {
                randomName = DarkRef.RandomBotName();
                trials++;
            }

            newInfo.username = randomName;
            prevNames.Add(randomName);

            newInfo.clan = "BOT";
            newInfo.rank = UnityEngine.Random.Range(1, 11);

            newBots[i]         = new BotPlayer();
            newBots[i].botInfo = newInfo;

            newBots[i].botStats           = new BotStats();
            newBots[i].team               = (byte)(i % 2);
            newBots[i].botStats.kills     = 0;
            newBots[i].botStats.deaths    = 0;
            newBots[i].botStats.headshots = 0;
            newBots[i].botStats.score     = 0;
            Topan.Network.SetServerInfo("bS" + i.ToString(), BotManager.ParseToBotFormat(newBots[i].botStats));
        }

        prevNames         = null;
        BotManager._sBots = newBots;
        Topan.Network.SetServerInfo("bots", newBots);
    }