示例#1
0
        //private bool playerIsOnAMatch(Lobby_Player lobby_Player)
        //{
        //    foreach (var item in matchs.Values)
        //    {
        //        if (item.matchPlayers.Contains(lobby_Player))
        //            return true;
        //    }
        //    return false;
        //}

        void CreateMatch(Lobby_Player matchOwner, ushort maxPlayersInMatch)
        {
            matchsCount++;
            if (matchs.ContainsKey(matchsCount))
            {
                matchsCount++;
            }

            Lobby_Match match = new Lobby_Match(matchsCount, maxPlayersInMatch, matchOwner);

            match.JoinMatch(matchOwner.client, true);

            matchs.Add(matchsCount, match);
        }
示例#2
0
        private void MessageReceived(object sender, MessageReceivedEventArgs e)
        {
            using (Message message = e.GetMessage() as Message)
            {
                using (DarkRiftReader r = message.GetReader())
                {
                    if (message.Tag == UDRMS_Tags.getLobbyMatchs)
                    {
                        GetLobbyRequestAndSend(e, r);
                    }
                    if (message.Tag == UDRMS_Tags.connectLobbyMatch)
                    {
                        ushort matchToJoin = r.ReadUInt16();

                        bool canJoin = matchs[matchToJoin].AddPlayerToMatch(players[e.Client]);

                        matchs[matchToJoin].JoinMatch(e.Client, canJoin);
                    }
                    if (message.Tag == UDRMS_Tags.createLobbyMatch)
                    {
                        foreach (Lobby_Match match in matchs.Values)
                        {
                            if (match.matchOwner == players[e.Client])
                            {
                                //TODO: With Host is Already created a Match Destroy Current Match
                                return;
                            }
                        }
                        CreateMatch(players[e.Client], maxPlayersPerMatch);
                    }
                    if (message.Tag == UDRMS_Tags.refreshLobbyMatchs)
                    {
                        using (DarkRiftWriter w = DarkRiftWriter.Create())
                        {
                            ushort totalLobbyPages = GetLobbyPages();
                            w.Write(totalLobbyPages);
                            using (Message m = Message.Create(UDRMS_Tags.refreshLobbyMatchs, w))
                                e.Client.SendMessage(m, SendMode.Reliable);
                        }
                    }
                    if (message.Tag == UDRMS_Tags.getLobbyMatchInfo)
                    {
                        Lobby_Player lobby_Player = players[e.Client];

                        if (lobby_Player.getCurrentMatch() != null)
                        {
                            //TODO: connect to match
                            Lobby_Match.SendToPlayerLobbyMatchInformation(lobby_Player);
                        }
                        else
                        {
                            //TODO: Send Player to Lobby or Do Nothing or Send Refresh
                        }
                    }
                    if (message.Tag == UDRMS_Tags.LoginInfo)
                    {
                        string playerName = r.ReadString();
                        players[e.Client].playerName = playerName;

                        //TODO: Can Login
                        bool canLogin = true;
                        using (DarkRiftWriter w = DarkRiftWriter.Create())
                        {
                            w.Write(canLogin);
                            using (Message m = Message.Create(UDRMS_Tags.LoginInfo, w))
                                e.Client.SendMessage(m, SendMode.Reliable);
                        }
                    }
                }
            }
        }