Inheritance: MonoBehaviour
Beispiel #1
0
 public void Awake()
 {
     Ins = this;
 }
Beispiel #2
0
 internal GameLobby CreateLobby()
 {
        int NlobbId = Lobbys.Count + 1;
        GameLobby NLobby = new GameLobby(NlobbId, Essential.GetUnixTimestamp());
        Lobbys.Add(NlobbId, NLobby);
        return Lobbys[NlobbId];
 }
Beispiel #3
0
 private void Start()
 {
     lobbyManager = FindObjectOfType <GameLobby>();
     //NOTE: When adding children to the available lobbies, just instantiate a new prefab and set the prefab's parent to availableLobbies.content
 }
 public static void Postfix(EDGCHOJDFNC __instance, [HarmonyArgument(0)] sbyte seconds) =>
 GameLobby.SetStartCounterPost(new GameLobbyWrapper(__instance), seconds);
 public static void Postfix(EDGCHOJDFNC __instance) =>
 GameLobby.PostMakePublicEvent(new GameLobbyWrapper(__instance));
Beispiel #6
0
        public async Task Report(string result)
        {
            result = result.ToLower();

            if (result == "win" || result == "loss")
            {
                var       userID = Context.User.Id;
                GameLobby lobby  = null;
                foreach (var lob in Session.GameLobbies)
                {
                    if (lob.State == GameLobby.LobbyState.Reporting && (lob.Captain1.DiscordID == userID || lob.Captain2.DiscordID == userID))
                    {
                        lobby = lob;
                    }
                }

                //Make sure user is captain of a lobby that's currently Playing.
                if (lobby != null)
                {
                    if (lobby.AwaitingConfirmation == false)
                    {
                        if (userID == lobby.Captain1.DiscordID && !lobby.Captain1.HasAlreadyReported)
                        {
                            if (result == "win")
                            {
                                lobby.WinningTeam = lobby.Team1;
                            }
                            else
                            {
                                lobby.WinningTeam = lobby.Team2;
                            }

                            lobby.Captain1.HasAlreadyReported = true;
                            lobby.AwaitingConfirmation        = true;
                            await SendEmbeddedMessageAsync("", "Awaiting confirmation from remaining Captain...", Colors.Info);
                        }
                        else if (userID == lobby.Captain2.DiscordID && !lobby.Captain2.HasAlreadyReported)
                        {
                            if (result == "win")
                            {
                                lobby.WinningTeam = lobby.Team2;
                            }
                            else
                            {
                                lobby.WinningTeam = lobby.Team1;
                            }

                            lobby.Captain2.HasAlreadyReported = true;
                            lobby.AwaitingConfirmation        = true;
                            await SendEmbeddedMessageAsync("", "Awaiting confirmation from remaining Captain...", Colors.Info);
                        }
                        else
                        {
                            await SendEmbeddedMessageAsync("Command Failed", "You have already reported the result of this match.", Colors.Danger);
                        }
                    }
                    else
                    {
                        if (userID == lobby.Captain1.DiscordID && !lobby.Captain1.HasAlreadyReported)
                        {
                            if (result == "win")
                            {
                                if (lobby.WinningTeam == lobby.Team1)
                                {
                                    lobby.ReportResult();
                                    await MatchCompleteEmbeddedMessageAsync(lobby);
                                }
                                else
                                {
                                    lobby.ResetReport();
                                    await SendEmbeddedMessageAsync("Command Failed", "Conflicting results have been reported. Both captains must report the result again, or contact an admin to resolve any conflicts.", Colors.Danger);
                                }
                            }
                            else
                            {
                                if (lobby.WinningTeam == lobby.Team2)
                                {
                                    lobby.ReportResult();
                                    await MatchCompleteEmbeddedMessageAsync(lobby);
                                }
                                else
                                {
                                    lobby.ResetReport();
                                    await SendEmbeddedMessageAsync("Command Failed", "Conflicting results have been reported. Both captains must report the result again, or contact an admin to resolve any conflicts.", Colors.Danger);
                                }
                            }
                        }
                        else if (userID == lobby.Captain2.DiscordID && !lobby.Captain2.HasAlreadyReported)
                        {
                            if (result == "win")
                            {
                                if (lobby.WinningTeam == lobby.Team2)
                                {
                                    lobby.ReportResult();
                                    await MatchCompleteEmbeddedMessageAsync(lobby);
                                }
                                else
                                {
                                    lobby.ResetReport();
                                    await SendEmbeddedMessageAsync("Command Failed", "Conflicting results have been reported. Both captains must report the result again, or contact an admin to resolve any conflicts.", Colors.Danger);
                                }
                            }
                            else
                            {
                                if (lobby.WinningTeam == lobby.Team1)
                                {
                                    lobby.ReportResult();
                                    await MatchCompleteEmbeddedMessageAsync(lobby);
                                }
                                else
                                {
                                    lobby.ResetReport();
                                    await SendEmbeddedMessageAsync("Command Failed", "Conflicting results have been reported. Both captains must report the result again, or contact an admin to resolve any conflicts.", Colors.Danger);
                                }
                            }
                        }
                        else
                        {
                            await SendEmbeddedMessageAsync("Command Failed", "You have already reported the result of this match.", Colors.Danger);
                        }
                    }
                }
                else
                {
                    await SendEmbeddedMessageAsync("Command Failed", "You must be the captain of a closed lobby to report results.", Colors.Danger);
                }
            }
            else
            {
                await SendEmbeddedMessageAsync("Command Failed", "You must report either a win or a loss. Type !report win or !report loss.", Colors.Danger);
            }
        }
 public static void Postfix(EDGCHOJDFNC __instance, [HarmonyArgument(0)] bool neverShow) =>
 GameLobby.PostGameStartingEvent(new GameLobbyWrapper(__instance), neverShow);
Beispiel #8
0
        public GameLobby Leave(string gameType, string lobbyId, string callingIp, string kickName = null)
        {
            new ValidationCheck()
            .Assert(ValidationCheck.BasicStringCheck(gameType, nameof(gameType)))
            .Assert(ValidationCheck.BasicStringCheck(lobbyId, nameof(lobbyId)))
            .Assert(ValidationCheck.BasicStringCheck(kickName, nameof(kickName)))
            .Assert(ValidationCheck.BasicStringCheck(callingIp, nameof(callingIp)))
            .Throw();

            gameType = gameType.ToUpperInvariant();
            lobbyId  = lobbyId.ToUpperInvariant();

            // unlike other methods, the Host can force a different user to Leave
            string lobbyKey = CreateKey(gameType, lobbyId);

            using (var r = new RedisClient(this.opt))
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                var foundGame = r.Send(RedisCommand.GET, lobbyKey);
                sw.Stop();

                if (foundGame == null)
                {
                    throw new LobbyException(404, "lobby does not exist");
                }
                string    lobbyStr = Encoding.UTF8.GetString(foundGame);
                GameLobby gl       = JsonConvert.DeserializeObject <GameLobby>(lobbyStr);
                new ValidationCheck()
                .Assert(gl.lobbyId == lobbyId, "lobby id changed")
                .Assert(gl.gameType == gameType, "gametype changed")
                .Throw();

                // Determine the client of the caller
                Client caller = gl.clients
                                .Concat(new Client[] { gl.host })
                                .First(c => string.Equals(c.ip, callingIp, StringComparison.InvariantCultureIgnoreCase));

                // Determine who is being kicked. If kickName is null, assume the caller is leaving.
                Client kickee = caller;
                if (!string.IsNullOrWhiteSpace(kickName))
                {
                    kickee = gl.clients
                             .Concat(new Client[] { gl.host })
                             .FirstOrDefault(c => string.Equals(c.name, kickName, StringComparison.InvariantCultureIgnoreCase));
                }

                new ValidationCheck()
                .Assert(caller != null, "caller must be in the client list")
                .Assert(kickee != null, "client to kick must be in the client list")
                .Throw();

                // Caller is the host and is leaving their own game
                if ((gl.host == caller) && (gl.host == kickee))
                {
                    sw.Start();
                    r.Send(RedisCommand.DEL, lobbyKey);
                    sw.Stop();
                }
                // Host is kicking someone or someone volunteered to leave
                else if ((gl.host == caller) || (kickee == caller))
                {
                    gl.clients.RemoveAll(c => string.Equals(c.name, kickName, StringComparison.InvariantCultureIgnoreCase));

                    sw.Start();
                    var resp = r.Send(RedisCommand.SET, lobbyKey, JsonConvert.SerializeObject(gl), "XX", "EX", ExpirationTimeSec);
                    sw.Stop();

                    if (resp == null)
                    {
                        throw new LobbyException(404, "lobby no longer exists");
                    }
                }
                else
                {
                    throw new LobbyException(403, "only the host can kick other users");
                }

                this.publishTimingStats(redisCategory, sw.ElapsedMilliseconds);

                return(gl);
            }
        }
Beispiel #9
0
        /// <summary>
        /// get a list of lobbies for a gametype.
        /// hidden games will not be returned
        /// </summary>
        /// <param name="gameType">gametype to search</param>
        /// <param name="metaKey">optional metadata key filter. the key must exist</param>
        /// <param name="metaValue">optional metadata value filter. the value must match for the given key.</param>
        /// <returns></returns>
        public List <GameLobby> Search(string gameType, string metaKey = null, string metaValue = null)
        {
            new ValidationCheck()
            .Assert(ValidationCheck.BasicStringCheck(gameType, nameof(gameType)))
            .Throw();

            gameType = gameType.ToUpperInvariant();

            // As it stands now, this search method will not scale well when there are many instances
            // of lobbies for the same game. maxSearchReturnSize*keyMult games are pulled first,
            // and then those are filtered by metaKey and metaValue. If none of those games in that
            // first scan match, then no games will be returned.
            // If this ever becomes a problem, I could create additional keys for metadata
            // inside Redis and use pattern matching SCAN on those keys. This just opens me up
            // to requiring a much larger redis instance, though, unless I want to further restrict
            // metaData.
            int keyMult = 1;
            Func <Dictionary <string, string>, bool> matches = (d) => true;

            if (!string.IsNullOrWhiteSpace(metaKey))
            {
                keyMult = 10;
                if (!string.IsNullOrWhiteSpace(metaValue))
                {
                    matches = (d) => d != null && d.ContainsKey(metaKey) && string.Equals(d[metaKey], metaValue);
                }
                else
                {
                    matches = (d) => d != null && d.ContainsKey(metaKey);
                }
            }

            var           foundGames = new List <GameLobby>();
            RedisPipeline pipe       = new RedisPipeline();

            using (var r = new RedisClient(this.opt))
            {
                // get initial set of keys
                Stopwatch sw = new Stopwatch();
                sw.Start();
                foreach (var searchRes in r.Scan(RedisCommand.SCAN, lobbyPrefix + gameType + "-[^" + SecretPrefix.ToString() + "]*"))
                {
                    foreach (var key in searchRes)
                    {
                        // build up messages to get more data
                        pipe.Send(RedisCommand.GET, key);

                        if (pipe.Length >= maxSearchReturnSize * keyMult)
                        {
                            break;
                        }
                    }
                    if (pipe.Length >= maxSearchReturnSize * keyMult)
                    {
                        break;
                    }
                }

                // get lobby data
                var readDetails = r.Send(pipe);
                this.publishTimingStats(redisCategory, sw.ElapsedMilliseconds);

                foreach (var lobby in readDetails)
                {
                    string    lobbyStr = Encoding.UTF8.GetString(lobby);
                    GameLobby gl       = JsonConvert.DeserializeObject <GameLobby>(lobbyStr);

                    if (matches(gl.metaData) && (gl.gameType == gameType))
                    {
                        foundGames.Add(gl);
                    }

                    if (foundGames.Count >= maxSearchReturnSize)
                    {
                        break;
                    }
                }
            }

            if (foundGames.Count == 0)
            {
                throw new LobbyException(404, "no games match search parameters");
            }

            return(foundGames);
        }
Beispiel #10
0
 private void Start()
 {
     instance = this;
 }
Beispiel #11
0
 private void OnEnable()
 {
     instance = this;
 }
Beispiel #12
0
        private static DataRow loginDeal(ref JObject loginRegisterMsg, ref LoginResult loginResult, out Player player, ref bool isReconnected)
        {
            string username = (string)loginRegisterMsg.GetValue("username");
            string password = (string)loginRegisterMsg.GetValue("password");

            //初始设置玩家信息为null
            player = null;
            //根据是否能找到该用户,返回状态参数
            DataRow playerInfo = null;     //玩家的信息

            do
            {
                //从数据库中获取用户名
                DataTable dataTable = SqlDbHelper.ExecuteDataTable
                                          ("select * from user_table where username = '******'");

                //如果不存在当前用户名
                if (dataTable.Rows.Count == 0)
                {
                    loginResult = LoginResult.USER_NOT_EXIST;
                    break;
                }

                //如果密码不正确
                playerInfo = dataTable.Rows[0];
                if ((string)playerInfo["password"] != password)
                {
                    loginResult = LoginResult.PASSWORD_NOT_CORRECT;
                    break;
                }

                //如果当前登录的用户名已登录
                GameLobby lobby = null;
                isReconnected = false;
                if (serverForm.server.players.TryGetValue(username, out lobby))
                {
                    //如果当前存在该玩家,但该玩家不在房间中,则移除该玩家
                    if (lobby == null)
                    {
                        serverForm.server.players.TryRemove(username, out lobby);
                        break;
                    }
                    //判断当前用户是否处于游戏中
                    if (lobby.getPlayer(username, out player) == true)
                    {
                        //如果正处在掉线的状态,进行断线重连
                        if (player.playerEnum == PlayerEnum.OFFLINE)
                        {
                            isReconnected = true;
                        }
                    }

                    if (isReconnected == false)
                    {
                        loginResult = LoginResult.USER_ALREADY_LOGIN;
                        break;
                    }
                }

                //如果用户名和密码都匹配,登录成功
                loginResult = LoginResult.LOGIN_SUCCESS;
            } while (false);

            //返回的结果
            return(playerInfo);
        }
Beispiel #13
0
 public override void OnStartLocalPlayer()
 {
     base.OnStartLocalPlayer();
     gameLobby = GameObject.Find("GameLobby").GetComponent <GameLobby>();
 }
 private void Queue_EnteredChampSelect(object sender, GameLobby e)
 {
     LoLClient.MainWindow.BeginChampionSelect(e);
 }
Beispiel #15
0
 private void Lobby_GameStarted(object sender, GameLobby game)
 {
     hasStarted = true;
     LoLClient.MainWindow.BeginChampionSelect(game);
 }
 public static void Postfix(EDGCHOJDFNC __instance) =>
 GameLobby.Start(new GameLobbyWrapper(__instance));
Beispiel #17
0
    void quickplayFunction()
    {
        GUI.Box(new Rect(Screen.width / 4 + 180, Screen.height / 2 - 30, 280, 50), "");

        int i = 0;

        HostData[] data = MasterServer.PollHostList();
        foreach (HostData element in data)
        {
            // Do not display NAT enabled games if we cannot do NAT punchthrough
            if (!(NATtester.filterNATHosts && element.useNat) && !element.passwordProtected)
            {
                //aHost=1;

                if (element.connectedPlayers < element.playerLimit)
                {
                    if (tryingToConnectquickplay)
                    {
                        string natText;
                        if (Network.useNat)
                        {
                            natText = " with option 1/2";
                        }
                        else
                        {
                            natText = " with option 2/2";
                        }
                        GUI.Label(new Rect(Screen.width / 4 + 200, Screen.height / 2 - 25, 285, 50), "Trying to connect to host " + (tryingToConnectquickplayNumber + 1) + "/" + data.Length + " " + natText);
                        if (!Network.useNat && lastquickplayConnectionTime + 0.75 <= Time.time || lastquickplayConnectionTime + 5.00 <= Time.time)
                        {
                            FailedConnRetry(false);
                        }
                        return;
                    }
                    if (!tryingToConnectquickplay && tryingToConnectquickplayNumber <= i)
                    {
                        Debug.Log("Trying to connect to game nr " + i + " & " + tryingToConnectquickplayNumber);
                        tryingToConnectquickplay       = true;
                        tryingToConnectquickplayNumber = i;
                        // Enable NAT functionality based on what the hosts if configured to do
                        lastMSConnectionAttemptForcedNat = element.useNat;
                        remoteIP       = element.ip;
                        remotePort[0]  = element.port;
                        Network.useNat = element.useNat;
                        int connectPort = element.port;
                        if (Network.useNat)
                        {
                            print("Using Nat punchthrough to connect");
                        }
                        else
                        {
                            print("Connecting directly to host");
                        }
                        Debug.Log("connecting to " + element.gameName + " " + element.ip + ":" + connectPort);
                        Network.Connect(element.ip, connectPort);
                        lastquickplayConnectionTime = Time.time;
                    }
                    i++;
                }
            }
        }

        //List is empty, d ont give up yet: Give MS 5 seconds to feed the list
        if (Time.time < quickplayModeStarted + 5)
        {
            //Debug.Log("PlayNow: delay up to 3 sec (no hosts yet)" );
            GUI.Label(new Rect(Screen.width / 4 + 200, Screen.height / 2 - 25, 280, 50), "Waiting for masterserver..." + Mathf.Ceil((quickplayModeStarted + 5) - Time.time));
            return;
        }

        if (!tryingToConnectquickplay)
        {
            Debug.Log("PlayNow: No games hosted, so hosting one ourselves");
            showMenu = false;
            GameLobby gameLobbyScript = GetComponent <GameLobby>();
            gameLobbyScript.EnableLobby();
        }
    }
Beispiel #18
0
        public async Task Pick(IUser pickedPlayer, IUser pickedPlayer2 = null)
        {
            //Check if user is the captain of a lobby that's currently picking players.
            var       discordID = Context.User.Id;
            GameLobby lobby     = Session.GetLobbyAbleToPickIn(discordID);

            if (lobby == null)
            {
                await SendEmbeddedMessageAsync("Command Failed", "You are not a captain of an open lobby.", Colors.Danger);

                return;
            }

            //Check if it's their turn to pick.
            if (!lobby.IsTurnToPick(discordID))
            {
                await SendEmbeddedMessageAsync("Command Failed", "It is not your turn to pick.", Colors.Danger);

                return;
            }

            //If first pick, must pick one player.
            if (lobby.IsFirstPick() && pickedPlayer2 != null)
            {
                await SendEmbeddedMessageAsync("Command Failed", "First pick must be one player!", Colors.Danger);

                return;
            }

            //If not first pick, must pick two players.
            if (!lobby.IsFirstPick() && pickedPlayer2 == null)
            {
                await SendEmbeddedMessageAsync("Command Failed", "You must pick two players.", Colors.Danger);

                return;
            }

            //Check if players are available.
            if (!lobby.IsAvailablePlayer(pickedPlayer.Id) || !(pickedPlayer2 == null ? true : lobby.IsAvailablePlayer(pickedPlayer2.Id)))
            {
                await SendEmbeddedMessageAsync("Command Failed", "Player is not available. Please choose players from the Remaining Players list.", Colors.Danger);

                return;
            }

            //Execute pick.
            if (pickedPlayer2 == null) //Pick one player.
            {
                lobby.PickPlayer(discordID, pickedPlayer.Id);
                await SendEmbeddedMessageAsync("", "Picked <@" + pickedPlayer.Id + ">...", Colors.Success);
            }
            else //Pick two players.
            {
                lobby.PickPlayer(discordID, pickedPlayer.Id, pickedPlayer2.Id);
                await SendEmbeddedMessageAsync("", "Picked <@" + pickedPlayer.Id + "> and <@" + pickedPlayer2.Id + ">...", Colors.Success);
            }

            //Start match once only one player is available.
            if (lobby.RemainingPlayers.Count == 1)
            {
                lobby.StartMatch();
                await MatchStartEmbeddedMessageAsync(lobby);
            }
            else
            {
                await PlayerPickedEmbeddedMessageAsync(lobby);
            }
        }