예제 #1
0
        void MyMultiplayerLobby_ClientLeft(ulong userId, ChatMemberStateChangeEnum stateChange)
        {
            Peer2Peer.CloseSession(userId);

            MySandboxGame.Log.WriteLineAndConsole("Player left: " + GetMemberName(userId) + " (" + userId + ")");
            MyTrace.Send(TraceWindow.Multiplayer, "Player left: " + stateChange.ToString());
        }
예제 #2
0
        void MyMultiplayerClient_ClientLeft(ulong user, ChatMemberStateChangeEnum stateChange)
        {
            if (user == ServerId)
            {
                RaiseHostLeft();
                return;
            }

            if (m_members.Contains(user))
            {
                m_members.Remove(user);

                MySandboxGame.Log.WriteLineAndConsole("Player disconnected: " + MySteam.API.Friends.GetPersonaName(user) + " (" + user + ")");

                MyTrace.Send(TraceWindow.Multiplayer, "Player disconnected: " + stateChange.ToString());

                if (MySandboxGame.IsGameReady && Sync.MyId != user)
                {
                    var clientLeft = new MyHudNotification(MyCommonTexts.NotificationClientDisconnected, 5000, level: MyNotificationLevel.Important);
                    clientLeft.SetTextFormatArguments(MySteam.API.Friends.GetPersonaName(user));
                    MyHud.Notifications.Add(clientLeft);
                }

                //Peer2Peer.CloseSession(user);
            }

            m_memberData.Remove(user);
        }
예제 #3
0
        void Matchmaking_LobbyChatUpdate(Lobby lobby, ulong changedUser, ulong makingChangeUser, ChatMemberStateChangeEnum stateChange)
        {
            //System.Diagnostics.Debug.Assert(MySession.Static != null);

            if (lobby.LobbyId == Lobby.LobbyId)
            {
                if (stateChange == ChatMemberStateChangeEnum.Entered)
                {
                    MySandboxGame.Log.WriteLineAndConsole("Player entered: " + MySteam.API.Friends.GetPersonaName(changedUser) + " (" + changedUser + ")");
                    MyTrace.Send(TraceWindow.Multiplayer, "Player entered");
                    Peer2Peer.AcceptSession(changedUser);

                    RaiseClientJoined(changedUser);

                    if (MySandboxGame.IsGameReady && changedUser != ServerId)
                    {
                        var playerJoined = new MyHudNotification(MySpaceTexts.NotificationClientConnected, 5000, level: MyNotificationLevel.Important);
                        playerJoined.SetTextFormatArguments(MySteam.API.Friends.GetPersonaName(changedUser));
                        MyHud.Notifications.Add(playerJoined);
                    }
                }
                else
                {
                    // Kicked client can be already removed from Clients
                    if (Sync.Clients.HasClient(changedUser))
                    {
                        RaiseClientLeft(changedUser, stateChange);
                    }

                    if (changedUser == ServerId)
                    {
                        MyTrace.Send(TraceWindow.Multiplayer, "Host left: " + stateChange.ToString());
                        RaiseHostLeft();

                        MyGuiScreenMainMenu.UnloadAndExitToMenu();
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                   messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionError),
                                                   messageText: MyTexts.Get(MySpaceTexts.MultiplayerErrorServerHasLeft)));

                        // Set new server
                        //ServerId = Lobby.GetOwner();

                        //if (ServerId == Sync.MyId)
                        //{
                        //    Lobby.SetLobbyData(HostNameTag, Sync.MyName);
                        //}
                    }
                    else if (MySandboxGame.IsGameReady)
                    {
                        var playerLeft = new MyHudNotification(MySpaceTexts.NotificationClientDisconnected, 5000, level: MyNotificationLevel.Important);
                        playerLeft.SetTextFormatArguments(MySteam.API.Friends.GetPersonaName(changedUser));
                        MyHud.Notifications.Add(playerLeft);
                    }
                }
            }
        }
예제 #4
0
        void Matchmaking_LobbyChatUpdate(Lobby lobby, ulong changedUser, ulong makingChangeUser, ChatMemberStateChangeEnum stateChange)
        {
            //System.Diagnostics.Debug.Assert(MySession.Static != null);

            if (lobby.LobbyId == Lobby.LobbyId)
            {
                if (stateChange == ChatMemberStateChangeEnum.Entered)
                {
                    MySandboxGame.Log.WriteLineAndConsole("Player entered: " + MySteam.API.Friends.GetPersonaName(changedUser) + " (" + changedUser + ")");
                    MyTrace.Send(TraceWindow.Multiplayer, "Player entered");
                    Peer2Peer.AcceptSession(changedUser);

                    // When some clients connect at the same time then some of them can have already added clients 
                    // (see function MySyncLayer.RegisterClientEvents which registers all Members in Lobby).
                    if (Sync.Clients == null || !Sync.Clients.HasClient(changedUser))
                    {
                        RaiseClientJoined(changedUser);

                        // Battles - send all clients, identities, players, factions as first message to client
                        if ((Battle || Scenario) && changedUser != Sync.MyId)
                        {
                            SendAllMembersDataToClient(changedUser);
                        }
                    }

                    if (MySandboxGame.IsGameReady && changedUser != ServerId)
                    {
                        // Player is able to connect to the battle which already started - player is then kicked and we do not want to show connected message in HUD.
                        bool showMsg = true;
                        if (MyFakes.ENABLE_BATTLE_SYSTEM && MySession.Static != null && MySession.Static.Battle && !BattleCanBeJoined)
                            showMsg = false;

                        if (showMsg)
                        {
                            var playerJoined = new MyHudNotification(MyCommonTexts.NotificationClientConnected, 5000, level: MyNotificationLevel.Important);
                            playerJoined.SetTextFormatArguments(MySteam.API.Friends.GetPersonaName(changedUser));
                            MyHud.Notifications.Add(playerJoined);
                        }
                    }
                }
                else
                {
                    // Kicked client can be already removed from Clients
                    if (Sync.Clients == null || Sync.Clients.HasClient(changedUser))
                        RaiseClientLeft(changedUser, stateChange);

                    if (changedUser == ServerId)
                    {
                        MyTrace.Send(TraceWindow.Multiplayer, "Host left: " + stateChange.ToString());
                        RaiseHostLeft();

                        MyGuiScreenMainMenu.UnloadAndExitToMenu();
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                            messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                            messageText: MyTexts.Get(MyCommonTexts.MultiplayerErrorServerHasLeft)));

                        // Set new server
                        //ServerId = Lobby.GetOwner();

                        //if (ServerId == Sync.MyId)
                        //{
                        //    Lobby.SetLobbyData(HostNameTag, Sync.MyName);
                        //}
                    }
                    else if (MySandboxGame.IsGameReady)
                    {
                        var playerLeft = new MyHudNotification(MyCommonTexts.NotificationClientDisconnected, 5000, level: MyNotificationLevel.Important);
                        playerLeft.SetTextFormatArguments(MySteam.API.Friends.GetPersonaName(changedUser));
                        MyHud.Notifications.Add(playerLeft);
                    }
                }
            }
        }
예제 #5
0
        void MyMultiplayerLobby_ClientLeft(ulong userId, ChatMemberStateChangeEnum stateChange)
        {
            if (userId == ServerId)
            {
                Peer2Peer.CloseSession(userId);
            }

            MySandboxGame.Log.WriteLineAndConsole("Player left: " + GetMemberName(userId) + " (" + userId + ")");
            MyTrace.Send(TraceWindow.Multiplayer, "Player left: " + stateChange.ToString());
        }
        void MyMultiplayerClient_ClientLeft(ulong user, ChatMemberStateChangeEnum stateChange)
        {
            if (user == ServerId)
            {
                RaiseHostLeft();
                return;
            }

            if (m_members.Contains(user))
            {
                m_members.Remove(user);

                MySandboxGame.Log.WriteLineAndConsole("Player disconnected: " + MySteam.API.Friends.GetPersonaName(user) + " (" + user + ")");

                MyTrace.Send(TraceWindow.Multiplayer, "Player disconnected: " + stateChange.ToString());

                if (MySandboxGame.IsGameReady && MySteam.UserId != user)
                {
                    var clientLeft = new MyHudNotification(MySpaceTexts.NotificationClientDisconnected, 5000, level: MyNotificationLevel.Important);
                    clientLeft.SetTextFormatArguments(MySteam.API.Friends.GetPersonaName(user));
                    MyHud.Notifications.Add(clientLeft);
                }

                Peer2Peer.CloseSession(user);
            }

            m_memberData.Remove(user);
        }                             
예제 #7
0
        void Matchmaking_LobbyChatUpdate(Lobby lobby, ulong changedUser, ulong makingChangeUser, ChatMemberStateChangeEnum stateChange)
        {
            //System.Diagnostics.Debug.Assert(MySession.Static != null);

            if (lobby.LobbyId == Lobby.LobbyId)
            {
                if (stateChange == ChatMemberStateChangeEnum.Entered)
                {
                    MySandboxGame.Log.WriteLineAndConsole("Player entered: " + MySteam.API.Friends.GetPersonaName(changedUser) + " (" + changedUser + ")");
                    MyTrace.Send(TraceWindow.Multiplayer, "Player entered");
                    Peer2Peer.AcceptSession(changedUser);

                    // When some clients connect at the same time then some of them can have already added clients
                    // (see function MySyncLayer.RegisterClientEvents which registers all Members in Lobby).
                    if (Sync.Clients == null || !Sync.Clients.HasClient(changedUser))
                    {
                        RaiseClientJoined(changedUser);
                    }

                    if (MySandboxGame.IsGameReady && changedUser != ServerId)
                    {
                        // Player is able to connect to the battle which already started - player is then kicked and we do not want to show connected message in HUD.
                        bool showMsg = true;
                        if (MyFakes.ENABLE_BATTLE_SYSTEM && MySession.Static != null && MySession.Static.Battle && !BattleCanBeJoined)
                        {
                            showMsg = false;
                        }

                        if (showMsg)
                        {
                            var playerJoined = new MyHudNotification(MyCommonTexts.NotificationClientConnected, 5000, level: MyNotificationLevel.Important);
                            playerJoined.SetTextFormatArguments(MySteam.API.Friends.GetPersonaName(changedUser));
                            MyHud.Notifications.Add(playerJoined);
                        }
                    }
                }
                else
                {
                    // Kicked client can be already removed from Clients
                    if (Sync.Clients == null || Sync.Clients.HasClient(changedUser))
                    {
                        RaiseClientLeft(changedUser, stateChange);
                    }

                    if (changedUser == ServerId)
                    {
                        MyTrace.Send(TraceWindow.Multiplayer, "Host left: " + stateChange.ToString());
                        RaiseHostLeft();

                        MySessionLoader.UnloadAndExitToMenu();
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                   messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                                   messageText: MyTexts.Get(MyCommonTexts.MultiplayerErrorServerHasLeft)));

                        // Set new server
                        //ServerId = Lobby.GetOwner();

                        //if (ServerId == Sync.MyId)
                        //{
                        //    Lobby.SetLobbyData(HostNameTag, Sync.MyName);
                        //}
                    }
                    else if (MySandboxGame.IsGameReady)
                    {
                        var playerLeft = new MyHudNotification(MyCommonTexts.NotificationClientDisconnected, 5000, level: MyNotificationLevel.Important);
                        playerLeft.SetTextFormatArguments(MySteam.API.Friends.GetPersonaName(changedUser));
                        MyHud.Notifications.Add(playerLeft);
                    }
                }
            }
        }
예제 #8
0
        void Matchmaking_LobbyChatUpdate(Lobby lobby, ulong changedUser, ulong makingChangeUser, ChatMemberStateChangeEnum stateChange)
        {
            //System.Diagnostics.Debug.Assert(MySession.Static != null);

            if (lobby.LobbyId == Lobby.LobbyId)
            {
                if (stateChange == ChatMemberStateChangeEnum.Entered)
                {
                    MySandboxGame.Log.WriteLineAndConsole("Player entered: " + MySteam.API.Friends.GetPersonaName(changedUser) + " (" + changedUser + ")");
                    MyTrace.Send(TraceWindow.Multiplayer, "Player entered");
                    Peer2Peer.AcceptSession(changedUser);

                    RaiseClientJoined(changedUser);

                    if (MySandboxGame.IsGameReady && changedUser != ServerId)
                    {
                        var playerJoined = new MyHudNotification(MySpaceTexts.NotificationClientConnected, 5000, level: MyNotificationLevel.Important);
                        playerJoined.SetTextFormatArguments(MySteam.API.Friends.GetPersonaName(changedUser));
                        MyHud.Notifications.Add(playerJoined);
                    }
                }
                else
                {
                    // Kicked client can be already removed from Clients
                    if (Sync.Clients.HasClient(changedUser))
                        RaiseClientLeft(changedUser, stateChange);

                    if (changedUser == ServerId)
                    {
                        MyTrace.Send(TraceWindow.Multiplayer, "Host left: " + stateChange.ToString());
                        RaiseHostLeft();

                        MyGuiScreenMainMenu.UnloadAndExitToMenu();
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                            messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionError),
                            messageText: MyTexts.Get(MySpaceTexts.MultiplayerErrorServerHasLeft)));

                        // Set new server
                        //ServerId = Lobby.GetOwner();

                        //if (ServerId == Sync.MyId)
                        //{
                        //    Lobby.SetLobbyData(HostNameTag, Sync.MyName);
                        //}
                    }
                    else if (MySandboxGame.IsGameReady)
                    {
                        var playerLeft = new MyHudNotification(MySpaceTexts.NotificationClientDisconnected, 5000, level: MyNotificationLevel.Important);
                        playerLeft.SetTextFormatArguments(MySteam.API.Friends.GetPersonaName(changedUser));
                        MyHud.Notifications.Add(playerLeft);
                    }
                }
            }
        }