public bool RemoveClient(VNetClient client) { if (client == null) { return(false); } if (VNetCommon.SHOW_LOGS) { UnityEngine.Debug.Log("VNet: Removing client " + client.GetName()); } // Callback when clietns are removed ClientRemovedCallback(client); // Check if we need to do a host migration m_netHost.CheckForHostLeft(client); // Remove from the client list and delete m_clientsByUID.Remove(client.GetUID()); // disconnect it client.Disconnect(); return(true); }
public void OnClientsWantsToLeave(VNetMessageLeaveSession leaveRequest) { VNetMessageLeaveSessionConfirm confirm = new VNetMessageLeaveSessionConfirm(); VNetClient client = leaveRequest._client; confirm.clientUID = client.GetUID(); client.SendNetMessage(confirm, false); client.SendPacketToClient(); RemoveClient(client); }
public void OnClientJoinRequest(VNetMessageJoinSession joinRequest) { // If i'm not the host, ignore this if (LocalIsHost() == false) { return; } // If this is for a separate session, ignore UInt64 sessionUID = VNetSession.Inst.GetSessionUID(); if (joinRequest.sessionUID != sessionUID) { return; } // Could be a dup, ignore if if that's the case if (VNetSession.Inst.GetClientByUID(joinRequest._packet.header.clientUID) != null) { return; } // Add this client VNetMessageNewClient nmc = new VNetMessageNewClient(); nmc.clientData = new VNetSimpleClientData(); nmc.clientData.active = 1; nmc.clientData.ip = joinRequest._packet.IP_Port.Address; nmc.clientData.port = joinRequest._packet.IP_Port.Port; nmc.clientData.uid = joinRequest._packet.header.clientUID; nmc.clientData.name = joinRequest.userName; nmc.clientData.role = joinRequest.role; nmc.sessionUID = sessionUID; VNet.Inst.SendToLobby(nmc, true); // Add the client to the local list VNetClient client = VNetSession.Inst.AddClient(joinRequest._packet.header.clientUID, joinRequest._packet.IP_Port); client.SetName(joinRequest.userName); client.SetRole(joinRequest.role); // Accept this client VNetMessageAcceptClient ac = new VNetMessageAcceptClient(); ac.clientUID = client.GetUID(); ac.sessionUID = sessionUID; ac.role = joinRequest.role; client.SendNetMessage(ac, true); }
// Functions public void CheckForHostLeft(VNetClient client) { if (client.GetUID() == m_hostUID) { if (VNetCommon.SHOW_LOGS) { UnityEngine.Debug.Log("VNet: The host left the session."); } // In the future, become the host based on some internal value Disconnect(); VNetSession.Inst.DisconnectAll(); } }
public void UpdateClients() { List <VNetClient> disconnectedClients = new List <VNetClient>(); foreach (KeyValuePair <UInt64, VNetClient> kvp in m_clientsByUID) { VNetClient client = kvp.Value; client.Update(); if (client.CheckForTimeout()) { disconnectedClients.Add(client); } } foreach (VNetClient client in disconnectedClients) { m_clientsByUID.Remove(client.GetUID()); } }