void OnServerUnregisterHost(NetworkMessage netMsg) { var msg = netMsg.ReadMessage <MasterMsgTypes.UnregisterHostMessage>(); // find the room var rooms = EnsureRoomsForGameType(msg.gameTypeName); if (!rooms.ServerList.ContainsKey(msg.gameName)) { //error Debug.Log("OnServerUnregisterHost game not found: " + msg.gameName); Debug.Log(string.Format("Failed to unregister host: Name: {0} : Addr: {1} Conn: {2}", msg.gameName, netMsg.conn.address, netMsg.conn.connectionId)); return; } var room = rooms.ServerList[msg.gameName]; if (room.connectionId != netMsg.conn.connectionId) { //error Debug.Log("OnServerUnregisterHost connection mismatch:" + room.connectionId); Debug.Log(string.Format("Failed to unregister host: Name: {0} : Addr: {1} Conn: {2}", msg.gameName, netMsg.conn.address, netMsg.conn.connectionId)); return; } rooms.ServerList.Remove(msg.gameName); Debug.Log(string.Format("Unregistered host: Name: {0} : Addr: {1} Conn: {2}", msg.gameName, netMsg.conn.address, netMsg.conn.connectionId)); // tell other players? var response = new MasterMsgTypes.RegisteredHostMessage(); response.resultCode = (int)MasterMsgTypes.NetworkMasterServerEvent.UnregistrationSucceeded; netMsg.conn.Send(MasterMsgTypes.UnregisteredHostId, response); }
// --------------- Application Handlers ----------------- void OnServerRegisterHost(NetworkMessage netMsg) { var msg = netMsg.ReadMessage <MasterMsgTypes.RegisterHostMessage>(); var rooms = EnsureRoomsForGameType(msg.gameTypeName); int result = (int)MasterMsgTypes.NetworkMasterServerEvent.RegistrationSucceeded; if (!rooms.AddHost(msg.gameName, msg.comment, netMsg.conn.address, msg.hostPort, netMsg.conn.connectionId)) { result = (int)MasterMsgTypes.NetworkMasterServerEvent.RegistrationFailedGameName; Debug.Log(string.Format("Failed to register host: Name: {0} : Comment: {1} : Addr: {2}:{3} Conn: {4}", msg.gameName, msg.comment, netMsg.conn.address, msg.hostPort, netMsg.conn.connectionId)); } else { Debug.Log(string.Format("Registered host: Name: {0} : Comment: {1} : Addr: {2}:{3} Conn: {4}", msg.gameName, msg.comment, netMsg.conn.address, msg.hostPort, netMsg.conn.connectionId)); } var response = new MasterMsgTypes.RegisteredHostMessage(); response.resultCode = result; netMsg.conn.Send(MasterMsgTypes.RegisteredHostId, response); }