private void CloseClient() { MyTrace.Send(TraceWindow.Multiplayer, "Multiplayer client closed"); if (m_clientJoined) { MyControlDisconnectedMsg msg = new MyControlDisconnectedMsg(); msg.Client = MySteam.UserId; SendControlMessage(ServerId, ref msg); } OnJoin = null; //TODO: Any better way? P2P needs to be closed from both sides. If closed right after Send, message //can stay not sent. Thread.Sleep(200); //WARN: If closed here, previous control message probably not come Peer2Peer.CloseSession(ServerId); CloseMemberSessions(); Peer2Peer.ConnectionFailed -= Peer2Peer_ConnectionFailed; Peer2Peer.SessionRequest -= Peer2Peer_SessionRequest; }
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()); }
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); }
private void CloseSession() { OnJoin = null; //WARN: If closed here, previous control message probably not come Peer2Peer.CloseSession(ServerId); Peer2Peer.ConnectionFailed -= Peer2Peer_ConnectionFailed; Peer2Peer.SessionRequest -= Peer2Peer_SessionRequest; }
protected void CloseMemberSessions() { for (int i = 0; i < MemberCount; i++) { var member = GetMemberByIndex(i); if (member != Sync.MyId && member == ServerId) { Peer2Peer.CloseSession(member); } } }
protected void CloseMemberSessions() { for (int i = 0; i < MemberCount; i++) { var member = GetMemberByIndex(i); if (member != MySteam.UserId) { Peer2Peer.CloseSession(member); } } }
void MyDedicatedServer_ClientLeft(ulong user, ChatMemberStateChangeEnum arg2) { Peer2Peer.CloseSession(user); MyLog.Default.WriteLineAndConsole("User left " + GetMemberName(user)); if (m_members.Contains(user)) { m_members.Remove(user); } if (m_pendingMembers.ContainsKey(user)) { m_pendingMembers.Remove(user); } if (m_waitingForGroup.Contains(user)) { m_waitingForGroup.Remove(user); } if (arg2 != ChatMemberStateChangeEnum.Kicked && arg2 != ChatMemberStateChangeEnum.Banned) { foreach (var member in m_members) { if (member != ServerId) { MyControlDisconnectedMsg msg = new MyControlDisconnectedMsg(); msg.Client = user; SendControlMessage(member, ref msg); } } } SteamSDK.SteamServerAPI.Instance.GameServer.SendUserDisconnect(user); m_memberData.Remove(user); }