void Peer2Peer_SessionRequest(ulong remoteUserId) { if (IsClientKickedOrBanned(remoteUserId)) { return; } if (IsServer || remoteUserId == ServerId) { Peer2Peer.AcceptSession(remoteUserId); } }
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 { 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); } } } }
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); } } } }